steps.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. const deletePreviewActionName = "porter-dev/porter-delete-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(serverURL, porterTokenSecretName string, projectID, clusterID, gitInstallationID uint, repoName, actionVersion string) GithubActionYAMLStep {
  38. return GithubActionYAMLStep{
  39. Name: "Create Porter preview env",
  40. Uses: fmt.Sprintf("%s@%s", createPreviewActionName, actionVersion),
  41. With: map[string]string{
  42. "cluster": fmt.Sprintf("%d", clusterID),
  43. "host": serverURL,
  44. "project": fmt.Sprintf("%d", projectID),
  45. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  46. "namespace": fmt.Sprintf("pr-${{ github.event.pull_request.number }}-%s", repoName),
  47. "pr_id": "${{ github.event.pull_request.number }}",
  48. "pr_name": "${{ github.event.pull_request.title }}",
  49. "installation_id": fmt.Sprintf("%d", gitInstallationID),
  50. "branch": "${{ github.head_ref }}",
  51. "action_id": "${{ github.run_id }}",
  52. "repo_owner": "${{ github.repository_owner }}",
  53. "repo_name": fmt.Sprintf("%s", repoName),
  54. },
  55. Timeout: 30,
  56. }
  57. }
  58. func getDeletePreviewEnvStep(serverURL, porterTokenSecretName string, projectID, clusterID, gitInstallationID uint, repoName, actionVersion string) GithubActionYAMLStep {
  59. return GithubActionYAMLStep{
  60. Name: "Delete Porter preview env",
  61. Uses: fmt.Sprintf("%s@%s", deletePreviewActionName, actionVersion),
  62. With: map[string]string{
  63. "cluster": fmt.Sprintf("%d", clusterID),
  64. "host": serverURL,
  65. "project": fmt.Sprintf("%d", projectID),
  66. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  67. "namespace": fmt.Sprintf("pr-${{ github.event.pull_request.number }}-%s", repoName),
  68. "installation_id": fmt.Sprintf("%d", gitInstallationID),
  69. "repo_owner": "${{ github.repository_owner }}",
  70. "repo_name": fmt.Sprintf("%s", repoName),
  71. },
  72. Timeout: 30,
  73. }
  74. }