steps.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. customNamespace bool,
  42. ) GithubActionYAMLStep {
  43. step := GithubActionYAMLStep{
  44. Name: "Create Porter preview env",
  45. Uses: fmt.Sprintf("%s@%s", createPreviewActionName, actionVersion),
  46. With: map[string]string{
  47. "cluster": fmt.Sprintf("%d", clusterID),
  48. "host": serverURL,
  49. "project": fmt.Sprintf("%d", projectID),
  50. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  51. "namespace": fmt.Sprintf("pr-${{ github.event.inputs.pr_number }}-%s",
  52. strings.ToLower(strings.ReplaceAll(repoName, "_", "-"))),
  53. "pr_id": "${{ github.event.inputs.pr_number }}",
  54. "pr_name": "${{ github.event.inputs.pr_title }}",
  55. "installation_id": fmt.Sprintf("%d", gitInstallationID),
  56. "pr_branch_from": "${{ github.event.inputs.pr_branch_from }}",
  57. "pr_branch_into": "${{ github.event.inputs.pr_branch_into }}",
  58. "action_id": "${{ github.run_id }}",
  59. "repo_owner": repoOwner,
  60. "repo_name": repoName,
  61. },
  62. Timeout: 30,
  63. }
  64. if customNamespace {
  65. step.With["namespace"] = "SET_CUSTOM_NAMESPACE_HERE"
  66. }
  67. return step
  68. }