diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..6e59755 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,25 @@ +name: Create Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Git + run: | + git config --global user.email "info@unconditional.day" + git config --global user.name "unconditionalbot" + + - name: Release + run: | + ./scripts/release.sh unconditionalday source $BOT_GITHUB_TOKEN + env: + BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..22a0026 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +calver=$(date +%Y-%m-%d) + +git tag -a "$calver" -m "Version $calver" +git push origin "$calver" + +OWNER=$1 +REPO=$2 +TOKEN=$3 + +response=$(curl -X POST "https://api.github.com/repos/$OWNER/$REPO/releases" \ + -H "Authorization: token $TOKEN" \ + -d '{ + "tag_name": "'"$calver"'", + "name": "'"$calver"'", + "body": "'"$calver"'" + }') + +release_id=$(echo "$response" | jq -r '.id') + +if [ "$release_id" != "null" ]; then + echo "Release $calver created successfully on GitHub (ID: $release_id)" +else + echo "Error creating the release on GitHub." + echo "$response" + git push --delete origin "$calver" + exit 1 +fi + +FILE_PATH="source.json" + +upload_url=$(echo "$response" | jq -r '.upload_url' | sed 's/{?name,label}//') + +curl -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ + --data-binary @"$FILE_PATH" \ + "$upload_url?name=source.json" + +echo "Attachment added successfully to the release."