From 9d9d6217c2aa205e1cd29cee3915c9520090c660 Mon Sep 17 00:00:00 2001 From: Alexandra Vedeler Date: Tue, 7 May 2024 16:07:24 +0200 Subject: [PATCH] added back missing workflows (#901) --- .github/{pr-labeler.yml => pr-labels.yml} | 0 .github/workflows/pr-labeler.yml | 19 +++ .github/workflows/scheduled-release.yml | 147 ++++++++++++++++++++++ 3 files changed, 166 insertions(+) rename .github/{pr-labeler.yml => pr-labels.yml} (100%) create mode 100644 .github/workflows/pr-labeler.yml create mode 100644 .github/workflows/scheduled-release.yml diff --git a/.github/pr-labeler.yml b/.github/pr-labels.yml similarity index 100% rename from .github/pr-labeler.yml rename to .github/pr-labels.yml diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml new file mode 100644 index 000000000..f0f212b0d --- /dev/null +++ b/.github/workflows/pr-labeler.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml new file mode 100644 index 000000000..3ec9834ff --- /dev/null +++ b/.github/workflows/scheduled-release.yml @@ -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/request-action@v2.x + 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/login-action@v3.1.0 + 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 }} \ No newline at end of file