-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: PR Labeler | ||
on: | ||
pull_request: | ||
types: [opened] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
pr-labeler: | ||
permissions: | ||
contents: read # for TimonVS/pr-labeler-action to read config file | ||
pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: TimonVS/pr-labeler-action@v5 | ||
with: | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
configuration-path: .github/pr-labels.yml # optional, .github/pr-labeler.yml is the default value |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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@v4 | ||
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@v6 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag: ${{ needs.getlatestrelease.outputs.RELEASEVERSION }} | ||
version: ${{ needs.getlatestrelease.outputs.RELEASEVERSION }} |