|
| 1 | +--- |
| 2 | +name: action-gitops |
| 3 | +description: | |
| 4 | + This action provides a standard way of adjusting replicas in a kustomize |
| 5 | + deployment and opening a PR to deploy the changes to a k8s cluster. |
| 6 | +
|
| 7 | + Other workflows may be added to this action in the future. |
| 8 | +
|
| 9 | +inputs: |
| 10 | + operation: |
| 11 | + description: The operation to run (adjust-replicas, etc) |
| 12 | + required: true |
| 13 | + environment: |
| 14 | + description: The environment to perform the operation on |
| 15 | + required: true |
| 16 | + service-name: |
| 17 | + description: The name of the service to perform the operation on |
| 18 | + required: true |
| 19 | + version: |
| 20 | + description: Version of Kustomize to use |
| 21 | + required: false |
| 22 | + default: 5.1.1 |
| 23 | + sha256-checksum: |
| 24 | + description: Checksum of Kustomize version |
| 25 | + required: false |
| 26 | + default: 3b30477a7ff4fb6547fa77d8117e66d995c2bdd526de0dafbf8b7bcb9556c85d |
| 27 | + git-commit-user: |
| 28 | + description: Name to add to the Git Commit Message |
| 29 | + required: false |
| 30 | + default: Kustomize Everything |
| 31 | + git-commit-email: |
| 32 | + description: Email to add to the Git Commit Message |
| 33 | + required: false |
| 34 | + default: kustomize-everything@users.noreply.github.com |
| 35 | + token: |
| 36 | + description: | |
| 37 | + The token to use for pushing to the repo. This should be a bot account |
| 38 | + with write access to the target repo, as well as PR access if it needs to |
| 39 | + open a PR. |
| 40 | + required: true |
| 41 | + helm-version: |
| 42 | + description: Helm Version to install |
| 43 | + default: 3.9.4 |
| 44 | + base-branch: |
| 45 | + description: The branch to open the PR against |
| 46 | + default: main |
| 47 | + replica_selector: |
| 48 | + description: The selector to use for adjusting replicas, if not provided, the service-name will be used |
| 49 | +runs: |
| 50 | + using: composite |
| 51 | + steps: |
| 52 | + - name: Checkout deployment repo |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + ref: main |
| 57 | + token: ${{ inputs.token }} |
| 58 | + |
| 59 | + # These variables are re-used by the run steps. |
| 60 | + - name: Shared ENV Setup |
| 61 | + shell: bash |
| 62 | + working-directory: ${{ inputs.working-directory }} |
| 63 | + env: |
| 64 | + ENV: ${{ inputs.environment }} |
| 65 | + PUSH_ENVIRONMENT_REGEX: ${{ steps.detect-push-environment.outputs.match }} |
| 66 | + PR_ENVIRONMENT_REGEX: ${{ steps.detect-pr-environment.outputs.match }} |
| 67 | + run: ${{ github.action_path }}/setup-shared-env.sh |
| 68 | + |
| 69 | + # Kustomize setup (this should be abstracted into a separate action repo) |
| 70 | + - name: Kustomize Setup |
| 71 | + uses: kustomize-everything/action-kustomize@v2.0.2 |
| 72 | + with: |
| 73 | + version: ${{ inputs.version }} |
| 74 | + sha256-checksum: ${{ inputs.sha256-checksum }} |
| 75 | + |
| 76 | + - name: Install yq |
| 77 | + uses: mikefarah/yq@v4.35.1 |
| 78 | + |
| 79 | + - name: Set Git Author |
| 80 | + shell: bash |
| 81 | + run: | |
| 82 | + git config --global user.name ${{ inputs.git-commit-user }} |
| 83 | + git config --global user.email ${{ inputs.git-commit-email }} |
| 84 | +
|
| 85 | + - name: Adjust Replicas |
| 86 | + shell: bash |
| 87 | + working-directory: ${{ inputs.working-directory }} |
| 88 | + if: ${{ inputs.operation == 'adjust-replicas' }} |
| 89 | + env: |
| 90 | + SELECTOR: ${{ github.event.inputs.replica_selector || github.event.inputs.service_name }} |
| 91 | + run: ${{ github.action_path }}/adjust-replicas.sh |
| 92 | + |
| 93 | + - name: Open ${{ inputs.operation }} PR to ${{ inputs.environment }} |
| 94 | + id: open-pr |
| 95 | + uses: peter-evans/create-pull-request@v5 |
| 96 | + with: |
| 97 | + title: ${{ inputs.operation }} on ${{ inputs.environment }} |
| 98 | + body: "${{ inputs.operation }} for ${{ env.SELECTOR }} to ${{ inputs.replicas }} in ${{ inputs.environment }}" |
| 99 | + base: ${{ input.base-branch }} |
| 100 | + branch: ${{ env.BRANCH_NAME }} |
| 101 | + delete-branch: true |
| 102 | + token: ${{ inputs.token }} |
| 103 | + |
| 104 | + - name: PR Opened or Updated |
| 105 | + if: ${{ steps.open-pr.outputs.pull-request-number && (steps.open-pr.outputs.pull-request-operation == 'created' || steps.open-pr.outputs.pull-request-operation == 'updated') }} |
| 106 | + shell: bash |
| 107 | + run: | |
| 108 | + echo "The ${{ inputs.operation }} PR for ${{ inputs.environment }} is waiting for |
| 109 | + deployment after PR review and merge." |
| 110 | + echo "Please review the k8s manifests in this PR and merge if ready |
| 111 | + to deploy to ${{ inputs.environment }}." |
| 112 | + echo "${{ steps.open-pr.outputs.pull-request-url }}" |
| 113 | +
|
| 114 | + - name: PR Closed |
| 115 | + if: ${{ steps.open-pr.outputs.pull-request-number && steps.open-pr.outputs.pull-request-operation == 'closed' }} |
| 116 | + shell: bash |
| 117 | + run: |- |
| 118 | + echo "The ${{ inputs.operation }} PR for ${{ inputs.environment }} has been closed as |
| 119 | + there are no changes detected." |
| 120 | + echo "${{ steps.open-pr.outputs.pull-request-url }}" |
0 commit comments