From 329a80d2e27a2c6bacf8dfdb372fccd7582e025c Mon Sep 17 00:00:00 2001 From: Nina Kylstad Date: Fri, 8 Nov 2024 08:53:52 +0100 Subject: [PATCH] chore: autogenerate github release each friday --- .github/scripts/release.sh | 61 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 23 +++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .github/scripts/release.sh create mode 100644 .github/workflows/release.yaml diff --git a/.github/scripts/release.sh b/.github/scripts/release.sh new file mode 100644 index 00000000000..456b1814a4b --- /dev/null +++ b/.github/scripts/release.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +set -e +set -u + +while [[ $# -gt 0 ]]; do + case $1 in + --github-token) + GITHUB_TOKEN="$2" + shift # pop option + shift # pop value + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + echo "Unknown argument $1" + exit 1 + ;; + esac +done + +CURRENT_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null) +CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ }) +FIRST_PART=${CURRENT_VERSION_PARTS[0]:1} +SECOND_PART=${CURRENT_VERSION_PARTS[1]} +COMMIT_ID=$(git rev-parse HEAD~0) +YEAR="$(date +"%Y")" + +echo "Git tag: $CURRENT_VERSION" +echo "First part: $FIRST_PART" +echo "Second part: $SECOND_PART" +echo "Second part+1: $(($SECOND_PART+1))" +echo "Commit ID: $COMMIT_ID" +echo "-------------------------------------" +echo "Year: $YEAR" +echo "-------------------------------------" + + +# Ensure that the version starts from 0 when the year changes +if [[ "$YEAR" == "$FIRST_PART" ]]; then + # Increment the second part of the version by 1 + NEW_VERSION="v${YEAR}.$(($SECOND_PART+1))" +else + # New year - start from 0 + NEW_VERSION="v${YEAR}.0" +fi + +echo "New version: $NEW_VERSION" + +echo "{\"tag_name\":\"$NEW_VERSION\",\"name\":\"${NEW_VERSION}\",\"draft\":true,\"prerelease\":false,\"generate_release_notes\":true}" + +curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/altinn/altinn-studio/releases \ + -d "{\"tag_name\":\"$NEW_VERSION\",\"name\":\"${NEW_VERSION}\",\"draft\":true,\"prerelease\":false,\"generate_release_notes\":true}" + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000000..41631773c2d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,23 @@ +name: Generate release for Altinn Studio +on: + schedule: + # run every friday at 15:00 + - cron: '0 9 * * 5' + +jobs: + generate-release: + name: Run release script + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + path: altinn-studio + fetch-tags: true + + - name: Run release script + working-directory: altinn-studio + run: | + bash .github/scripts/release.sh \ + --github-token ${{ secrets.GITHUB_TOKEN }} \ +