Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Release Workflow #3

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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 }}
39 changes: 39 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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."
Loading