steps.go 2.2 KB

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