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

Automatic release part 2 #116

Merged
merged 9 commits into from
Nov 28, 2024
Merged
Changes from 3 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
81 changes: 81 additions & 0 deletions .github/workflows/release-post-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Post-Merge Release Actions

on:
pull_request:
types: [closed]
branches:
- 'main'

permissions:
contents: write
pull-requests: write

env:
GITHUB_USER: "datavisyn-bot"
GITHUB_TOKEN: ${{ secrets.DATAVISYN_BOT_REPO_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }}

jobs:
post_release:
if: ${{ github.event.pull_request.merged == true && startsWith(github.event.pull_request.title, 'Release') }}
runs-on: ubuntu-22.04
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
fetch-depth: 0

- name: Create and Push Tag
run: |
TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')"
git tag "$TAG_NAME"
git push origin "$TAG_NAME"

- name: Generate Release Notes
id: generate-release-notes
run: |
TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')"
response=$(curl -s -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/${{ github.repository }}/releases/generate-notes \
-d "$(jq -n --arg tag_name "$TAG_NAME" \
--arg target_commitish "main" \
'{tag_name: $tag_name, target_commitish: $target_commitish}')")
echo "$response" | jq -r '.body' > release_notes.txt

- name: Create GitHub Release
run: |
TAG_NAME="v$(echo "$PR_TITLE" | awk '{print $2}')"
RELEASE_NOTES=$(cat release_notes.txt)
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository_owner }}/${{ github.event.repository.name }}/releases \
-d '{
"tag_name": "'"$TAG_NAME"'",
"target_commitish": "main",
"name": "'"$TAG_NAME"'",
"body": "'"$RELEASE_NOTES"'",
"draft": false,
"prerelease": false
}'

- name: Merge Main into Develop
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "<>"
git checkout develop
git pull origin main
git push origin develop

- name: Update Package Version for Next Development Cycle
run: |
CURRENT_VERSION=$(jq -r '.version' package.json)
NEW_VERSION=$(echo "$CURRENT_VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print $0"-SNAPSHOT"}')
jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json

git add package.json
git commit -m "chore: prepare next dev release"
git push origin develop