Merge pull request #343 from bcgov/DAP-1003-extra-metadata #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update API Image Tag in GitOps Repo | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- backend/** | |
jobs: | |
update-gitops-image-tag: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get PR Number | |
id: get-pr-number | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const { data: pulls } = await github.rest.pulls.list({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'all', | |
}); | |
const pr = pulls.find(pr => pr.merge_commit_sha === process.env.GITHUB_SHA); | |
if (pr) { | |
return pr.number | |
} else { | |
return '' | |
} | |
result-encoding: string | |
# Install yaml parser | |
- name: Install yq | |
run: | | |
curl -Lo yq "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64" | |
chmod +x yq | |
mv yq /home/runner/bin | |
# Add deploy key to runner | |
- name: Setup SSH | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.GITOPS_REPO_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts | |
# Make changes to image tag within GitOps repo | |
- name: Clone, Update, and Commit Changes | |
run: | | |
git clone [email protected]:bcgov-c/tenant-gitops-ede50e.git | |
cd tenant-gitops-ede50e | |
FILE_PATH="grs-dats/values-dev.yaml" | |
NEW_TAG="${{ steps.get-pr-number.outputs.result }}" | |
yq e ".api_v2.image.tag = \"$NEW_TAG\"" -i "$FILE_PATH" | |
git config user.email "[email protected]" | |
git config user.name "Bottle7" | |
git add "$FILE_PATH" | |
git commit -m "Update API image tag to $NEW_TAG" | |
git push | |