-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (132 loc) · 5.25 KB
/
scheduled-release.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Schedule a release and image
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 3"
env:
REGISTRY: ghcr.io
IMAGE_NAME: altinn/altinn-access-management-frontend
jobs:
getlatestrelease:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
issues: write
packages: write
steps:
- name: setup current year
id: get_year
run: |
echo "currentyear=$(date +%Y)" >> $GITHUB_ENV
- name: Get Latest Release using github api
uses: octokit/[email protected]
continue-on-error: true
id: get_latest_release_version
with:
route: GET /repos/altinn/altinn-access-management-frontend/releases/latest
mediaType: | # The | is significant!
format: raw
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: print status
run: "echo Release could not be found. Request failed with status '${{ steps.get_latest_release_version.outputs.status }}'"
- name: split release version f.ex v2023.1 will be split into output0 v2023 and output1 1
if: ${{ steps.get_latest_release_version.outputs.status == '200' }}
uses: winterjung/split@v2
id: split
with:
msg: "${{ fromJson(steps.get_latest_release_version.outputs.data).tag_name }}"
separator: '.'
- name: split 'v' and year f.ex v2023 will be split into output0 v and output1 2023
if: ${{ steps.get_latest_release_version.outputs.status == '200' }}
uses: winterjung/split@v2
id: splitv
with:
msg: "${{steps.split.outputs._0}}"
separator: 'v'
- name: Increment release version f.ex the release version for the year is incremented
if: ${{ steps.get_latest_release_version.outputs.status == '200' }}
id: update_version
env:
NUM: ${{ steps.split.outputs._1 }}
run: |
echo "VERSION=$(($NUM + 1))" >> $GITHUB_ENV
- name: Format new release version when there is atleast 1 previous release. If the release is created in the new year, the current year is set and the identity is reset to 1.
if: ${{ steps.get_latest_release_version.outputs.status == '200' }}
id: format_version
env:
RELEASE_YEAR: ${{steps.splitv.outputs._1}}
run: |
if [ ${{env.currentyear}} -gt ${{env.RELEASE_YEAR}} ]
then
echo "RELEASEVERSION=v${{env.currentyear}}.1" >> $GITHUB_OUTPUT
else
echo "RELEASEVERSION=v${{env.RELEASE_YEAR}}.${{env.VERSION}}" >> $GITHUB_OUTPUT
fi
- name: Set release version if 0 releases. The initial version is set to the v{currentyear}.{identity} f.ex v2023.1
id: releaseversion
run: |
if [ ${{ steps.get_latest_release_version.outputs.status }} = '200' ]
then
echo "RELEASE=${{ steps.format_version.outputs.RELEASEVERSION }}" >> $GITHUB_OUTPUT
else
echo "RELEASE=v${{env.currentyear}}.1" >> $GITHUB_OUTPUT
fi
outputs:
RELEASEVERSION: ${{ steps.releaseversion.outputs.RELEASE }}
tag:
name: Tag image with release version
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
issues: write
packages: write
needs: [getlatestrelease]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: setup git config
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "github-actions[bot]"
git config user.email ""
git config -l | grep url
- name: Get last commit id
id: get_commit_sha
run: echo "commitid=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Login to GHCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: version
uses: battila7/get-version-action@v2
- name: Add Version tag to Docker Image
uses: shrink/actions-docker-registry-tag@v3
with:
registry: ${{ env.REGISTRY }}
repository: '${{ env.IMAGE_NAME }}'
target: '${{ steps.get_commit_sha.outputs.commitid }}'
tags: ${{ needs.getlatestrelease.outputs.RELEASEVERSION }}
update_release_draft:
name: Release Drafter with releaseversion that was formatted
needs: [getlatestrelease,tag]
permissions:
contents: write # for release-drafter/release-drafter to create a github release
pull-requests: write # for release-drafter/release-drafter to add label to PR
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ needs.getlatestrelease.outputs.RELEASEVERSION }}
version: ${{ needs.getlatestrelease.outputs.RELEASEVERSION }}