-
Notifications
You must be signed in to change notification settings - Fork 2
65 lines (54 loc) · 1.71 KB
/
update-gitops-repo-api-v2.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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