Skip to content

Commit

Permalink
chore: autogenerate github release each friday
Browse files Browse the repository at this point in the history
  • Loading branch information
nkylstad committed Nov 8, 2024
1 parent a702c6c commit 329a80d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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}"

23 changes: 23 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }} \

0 comments on commit 329a80d

Please sign in to comment.