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

chore(release): add gh workflow for planing release #9

Merged
merged 2 commits into from
Nov 9, 2024
Merged
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
77 changes: 77 additions & 0 deletions .github/workflows/plan-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: "🚀 Release on Comment"

on:
issue_comment:
types: [created]

jobs:
release:
runs-on: ubuntu-latest
if: github.event.issue.pull_request # Ensures it's triggered only on PR comments
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4

- name: ⬢ Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16" # or the version you need

- name: 💬 Parse comment for release version
id: parse_version
run: |
COMMENT_BODY="${{ github.event.comment.body }}"
if [[ $COMMENT_BODY =~ ^release\ ([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "RELEASE_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
else
echo "Comment does not match 'release <semver>' format."
exit 1
fi

- name: 👍 Add thumbs-up reaction to comment
run: |
COMMENT_ID=${{ github.event.comment.id }}
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.squirrel-girl-preview+json" \
-X POST "https://api.github.com/repos/${{ github.repository }}/issues/comments/$COMMENT_ID/reactions" \
-d '{"content":"+1"}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}



- name: ✍️ Update package.json version
run: |
jq '.version = env.RELEASE_VERSION' package.json > temp.json && mv temp.json package.json
shell: bash

- name: 🔖 Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "chore(release): Set version to $RELEASE_VERSION"

- name: 📤 Push commit
run: |
git push origin HEAD:${{ github.head_ref }}

- name: ✍️ Update PR title
env:
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
run: |
DATE=$(date +'%Y-%m-%d')
gh pr edit ${{ github.event.issue.number }} --title "chore(release): $DATE ($RELEASE_VERSION)"
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 📣 Post release confirmation comment
run: |
DATE=$(date +'%Y-%m-%d')
RELEASE_VERSION=${{ env.RELEASE_VERSION }}
COMMENT_BODY="### 🚀 Release planned: $DATE ($RELEASE_VERSION)"
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-X POST "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
-d "{\"body\": \"$COMMENT_BODY\"}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}