steps.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. const deletePreviewActionName = "porter-dev/porter-delete-preview-action"
  9. func getCheckoutCodeStep() GithubActionYAMLStep {
  10. return GithubActionYAMLStep{
  11. Name: "Checkout code",
  12. Uses: "actions/checkout@v2.3.4",
  13. }
  14. }
  15. func getSetTagStep() GithubActionYAMLStep {
  16. return GithubActionYAMLStep{
  17. Name: "Set Github tag",
  18. ID: "vars",
  19. Run: `echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"`,
  20. }
  21. }
  22. func getUpdateAppStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string, appNamespace, actionVersion string) GithubActionYAMLStep {
  23. return GithubActionYAMLStep{
  24. Name: "Update Porter App",
  25. Uses: fmt.Sprintf("%s@%s", updateAppActionName, actionVersion),
  26. With: map[string]string{
  27. "app": appName,
  28. "cluster": fmt.Sprintf("%d", clusterID),
  29. "host": serverURL,
  30. "project": fmt.Sprintf("%d", projectID),
  31. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  32. "tag": "${{ steps.vars.outputs.sha_short }}",
  33. "namespace": appNamespace,
  34. },
  35. Timeout: 20,
  36. }
  37. }
  38. func getCreatePreviewEnvStep(
  39. serverURL, porterTokenSecretName string,
  40. projectID, clusterID, gitInstallationID uint,
  41. repoOwner, repoName, actionVersion string,
  42. ) GithubActionYAMLStep {
  43. return 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. }
  65. func getDeletePreviewEnvStep(serverURL, porterTokenSecretName string, projectID, clusterID uint, repoName, actionVersion string) GithubActionYAMLStep {
  66. return GithubActionYAMLStep{
  67. Name: "Delete Porter preview env",
  68. Uses: fmt.Sprintf("%s@%s", deletePreviewActionName, actionVersion),
  69. With: map[string]string{
  70. "cluster": fmt.Sprintf("%d", clusterID),
  71. "host": serverURL,
  72. "project": fmt.Sprintf("%d", projectID),
  73. "token": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
  74. "deployment_id": "${{ github.event.inputs.deployment_id }}",
  75. },
  76. Timeout: 30,
  77. }
  78. }