steps.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package actions
  2. import "fmt"
  3. func getCheckoutCodeStep() GithubActionYAMLStep {
  4. return GithubActionYAMLStep{
  5. Name: "Checkout code",
  6. Uses: "actions/checkout@v2.3.4",
  7. }
  8. }
  9. const download string = `
  10. name=$(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_Linux_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \")
  11. name=$(basename $name)
  12. curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
  13. unzip -a $name
  14. rm $name
  15. chmod +x ./porter
  16. sudo mv ./porter /usr/local/bin/porter
  17. `
  18. func getDownloadPorterStep() GithubActionYAMLStep {
  19. return GithubActionYAMLStep{
  20. Name: "Download Porter",
  21. ID: "download_porter",
  22. Run: download,
  23. }
  24. }
  25. const configure string = `
  26. porter auth login --token ${{secrets.%s}}
  27. sudo porter docker configure
  28. `
  29. func getConfigurePorterStep(porterTokenSecretName string) GithubActionYAMLStep {
  30. return GithubActionYAMLStep{
  31. Name: "Configure Porter",
  32. ID: "configure_porter",
  33. Run: fmt.Sprintf(configure, porterTokenSecretName),
  34. }
  35. }
  36. const dockerBuildPush string = `
  37. docker build . --file %s -t %s:$(git rev-parse --short HEAD)
  38. docker push %s:$(git rev-parse --short HEAD)
  39. `
  40. func getDockerBuildPushStep(dockerFilePath, repoURL string) GithubActionYAMLStep {
  41. return GithubActionYAMLStep{
  42. Name: "Docker build, push",
  43. ID: "docker_build_push",
  44. Run: fmt.Sprintf(dockerBuildPush, dockerFilePath, repoURL, repoURL),
  45. }
  46. }
  47. const deployPorter string = `
  48. curl -X POST "https://dashboard.getporter.dev/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)&repository=%s"
  49. `
  50. func deployPorterWebhookStep(webhookTokenSecretName, repoURL string) GithubActionYAMLStep {
  51. return GithubActionYAMLStep{
  52. Name: "Deploy on Porter",
  53. ID: "deploy_porter",
  54. Run: fmt.Sprintf(deployPorter, webhookTokenSecretName, repoURL),
  55. }
  56. }