-
Notifications
You must be signed in to change notification settings - Fork 4
84 lines (69 loc) · 2.85 KB
/
update-chart.yml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Update Helm Chart Version and Create Pull Request
on:
schedule:
- cron: "*/5 * * * *" # Runs every 5 minutes
workflow_dispatch: # Allows manual trigger
permissions:
id-token: write
contents: write
pull-requests: write
env:
REGISTRY: ${{ secrets.ALTINN_REGISTRY }}
APP_NAME: altinn-receipt
jobs:
update-helm-chart:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: 'Azure login'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Get latest Helm chart version from ACR
id: get-latest-version
run: |
latest_version=$(az acr repository show-tags --name ${{ env.REGISTRY }} --repository charts/${{ env.APP_NAME }} --output tsv --orderby time_desc --top 1)
# Replace `_` with `+`, this is due to the oci repo not supporting `+` in tags
echo "latest_version=${latest_version//_/+}" >> $GITHUB_ENV
- name: Extract current version from YAML
id: extract-current-version
run: |
current_version=$(yq eval '.spec.chart.spec.version' .deploy/app.yaml)
echo "current_version=$current_version" >> $GITHUB_ENV
- name: Compare versions
id: compare-versions
run: |
if [ "${{ env.latest_version }}" != "${{ env.current_version }}" ]; then
echo "::set-output name=should_update::true"
else
echo "::set-output name=should_update::false"
fi
- name: Update YAML file
if: steps.compare-versions.outputs.should_update == 'true'
run: |
yq eval '.spec.chart.spec.version = "${{ env.latest_version }}"' -i .deploy/app.yaml
- name: Create Pull Request
if: steps.compare-versions.outputs.should_update == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
delete-branch: true
commit-message: "Update Helm chart to version ${{ env.latest_version }}"
title: "Update Helm chart to version ${{ env.latest_version }}"
body: |
- The Helm chart has been updated to version ${{ env.latest_version }}.
Auto-generated by GitHub Actions.
branch: update-helm-chart-${{ env.latest_version }}
- name: Clean up
if: steps.compare-versions.outputs.should_update == 'true'
run: git checkout main
- name: Send Trace to Azure Monitor
uses: altinn/altinn-platform/actions/send-ci-cd-trace@v1.0.1
with:
connection_string: ${{ secrets.APP_INSIGHTS_CONNECTION_STRING }}
app: "${{ env.APP_NAME }}"
team: "core"
repo_token: ${{ secrets.GITHUB_TOKEN }}