steps.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package actions
  2. import "fmt"
  3. const download string = `
  4. name=$(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_Linux_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \")
  5. name=$(basename $name)
  6. curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
  7. unzip -a $name
  8. rm $name
  9. chmod +x ./porter
  10. sudo mv ./porter /usr/local/bin/porter
  11. `
  12. func getDownloadPorterStep() GithubActionYAMLStep {
  13. return GithubActionYAMLStep{
  14. Name: "Download Porter",
  15. ID: "download_porter",
  16. Run: download,
  17. }
  18. }
  19. const configure string = `
  20. porter auth login --token ${{secrets.%s}}
  21. porter docker configure
  22. `
  23. func getConfigurePorterStep(porterTokenSecretName string) GithubActionYAMLStep {
  24. return GithubActionYAMLStep{
  25. Name: "Configure Porter",
  26. ID: "configure_porter",
  27. Run: fmt.Sprintf(configure, porterTokenSecretName),
  28. }
  29. }
  30. const dockerBuildPush string = `
  31. docker build . --file %s -t %s:$(git rev-parse --short HEAD)
  32. docker push %s:$(git rev-parse --short HEAD)
  33. `
  34. func getDockerBuildPushStep(dockerFilePath, repoURL string) GithubActionYAMLStep {
  35. return GithubActionYAMLStep{
  36. Name: "Docker build, push",
  37. ID: "docker_build_push",
  38. Run: fmt.Sprintf(dockerBuildPush, dockerFilePath, repoURL, repoURL),
  39. }
  40. }
  41. const deployPorter string = `
  42. curl -X POST 'https://dashboard.getporter.dev/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)&repository=%s'
  43. `
  44. func deployPorterWebhookStep(webhookTokenSecretName, repoURL string) GithubActionYAMLStep {
  45. return GithubActionYAMLStep{
  46. Name: "Deploy on Porter",
  47. ID: "deploy_porter",
  48. Run: fmt.Sprintf(deployPorter, webhookTokenSecretName, repoURL),
  49. }
  50. }