diff --git a/.github/workflows/reusable-update-docker-tags.yaml b/.github/workflows/reusable-update-docker-tags.yaml new file mode 100644 index 000000000..73e2e8f6d --- /dev/null +++ b/.github/workflows/reusable-update-docker-tags.yaml @@ -0,0 +1,94 @@ +name: "update docker tags" + +on: + push: + branches: + - "*" + tags: + - '*' + pull_request_target: + types: + - opened + - edited + - synchronize + - reopened + workflow_call: + inputs: + commit_message: + description: "The commit message you want to include with the changes" + required: true + type: string + # example: Deployed to dev + file_to_update_full_path: + description: "The full path to the file you want to change" + required: true + type: string + # example: terraform-environments/aws/dev/helm/my-app/main.tf + update_tag_to: + description: "The tag to update to" + required: true + type: string + # example: ${{needs.build_image.outputs.docker_tag_with_sha}} + repo_name_to_make_changes_in: + description: "The repository name to make changes into" + required: true + type: string + # example: / + repo_name_to_make_changes_in_branch: + description: "The branch in the repository to make changes to" + required: true + type: string + # example: main + secrets: + github_personal_access_token_for_repo_to_make_changes_in: + required: true + +permissions: + pull-requests: write + +jobs: + update_docker_tag: + runs-on: ubuntu-latest + env: + REPLACE_FILE_PATH: ${{ inputs.file_to_update_full_path }} + steps: + - run: echo "hello...${{ inputs.commit_message }}" + + - name: image_tag + run: echo "${{ inputs.update_tag_to }}" + + # Checkout the repo + - name: Checkout + uses: actions/checkout@v2 + with: + repository: ${{ inputs.repo_name_to_make_changes_in }} + ref: ${{ inputs.repo_name_to_make_changes_in_branch }} + token: ${{ secrets.github_personal_access_token_for_repo_to_make_changes_in }} + + # Update the docker tags in the TF/helm deployment + - name: Update dev image tag + uses: jacobtomlinson/gha-find-replace@0.1.4 + env: + REPLACE_FILE_PATH: ${{ env.REPLACE_FILE_PATH }} + with: + find: "docker_tag\\s+=\\s+\".*\"" + replace: "docker_tag = \"${{ inputs.update_tag_to }}\"" + include: ${{ env.REPLACE_FILE_PATH }} + + # Print the changes made + - name: Check output + run: | + echo "ref: ${{ github.ref }}" + echo "head_ref: ${{ github.head_ref }}" + echo "base_ref: ${{ github.base_ref }}" + echo "update_tag_to: ${{ inputs.update_tag_to }}" + cat ${{ env.REPLACE_FILE_PATH }} + git diff + + # Commit and push changes + - name: Update deploy docker tags file + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "${{ inputs.commit_message }} | tags: ${{ inputs.update_tag_to }}" + file_pattern: ${{ env.REPLACE_FILE_PATH }} + branch: ${{ inputs.repo_name_to_make_changes_in_branch }}