steps.go 2.2 KB

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