steps.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package actions
  2. import (
  3. "fmt"
  4. )
  5. const updateAppActionName = "porter-dev/porter-update-action"
  6. const createPreviewActionName = "porter-dev/porter-preview-action"
  7. func getCheckoutCodeStep() GithubActionYAMLStep {
  8. return GithubActionYAMLStep{
  9. Name: "Checkout code",
  10. Uses: "actions/checkout@v2.3.4",
  11. }
  12. }
  13. func getSetTagStep() GithubActionYAMLStep {
  14. return GithubActionYAMLStep{
  15. Name: "Set Github tag",
  16. ID: "vars",
  17. Run: `echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"`,
  18. }
  19. }
  20. func getUpdateAppStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string, appNamespace, actionVersion string) GithubActionYAMLStep {
  21. return GithubActionYAMLStep{
  22. Name: "Update Porter App",
  23. Uses: fmt.Sprintf("%s@%s", updateAppActionName, actionVersion),
  24. With: map[string]string{
  25. "app": appName,
  26. "cluster": fmt.Sprintf("%d", clusterID),
  27. "host": serverURL,
  28. "project": fmt.Sprintf("%d", projectID),
  29. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  30. "tag": "${{ steps.vars.outputs.sha_short }}",
  31. "namespace": appNamespace,
  32. },
  33. Timeout: 20,
  34. }
  35. }
  36. func getCreatePreviewEnvStep(serverURL, porterTokenSecretName string, projectID, clusterID, gitInstallationID uint, repoName, actionVersion string) GithubActionYAMLStep {
  37. return GithubActionYAMLStep{
  38. Name: "Create Porter preview env",
  39. Uses: fmt.Sprintf("%s@%s", createPreviewActionName, actionVersion),
  40. With: map[string]string{
  41. "cluster": fmt.Sprintf("%d", clusterID),
  42. "host": serverURL,
  43. "project": fmt.Sprintf("%d", projectID),
  44. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  45. "namespace": fmt.Sprintf("pr-${{ github.event.pull_request.number }}-%s", repoName),
  46. "pr_id": "${{ github.event.pull_request.number }}",
  47. "installation_id": fmt.Sprintf("%d", gitInstallationID),
  48. "branch": "${{ github.head_ref }}",
  49. "action_id": "${{ github.run_id }}",
  50. },
  51. Timeout: 30,
  52. }
  53. }