Skip to content

Commit

Permalink
Re-usable workflow to update a remote repository (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
sekka1 authored Mar 5, 2022
1 parent d2d23f3 commit 485e625
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/reusable-update-docker-tags.yaml
Original file line number Diff line number Diff line change
@@ -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 org/owner>/<repo name>
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/[email protected]
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 }}

0 comments on commit 485e625

Please sign in to comment.