Skip to content

Generate GitHub Release Issue/PR #23

Generate GitHub Release Issue/PR

Generate GitHub Release Issue/PR #23

name: Generate GitHub Release Issue/PR
on:
workflow_dispatch: {}
schedule:
# Runs at 08:00 Taipei time (UTC+8) on Monday.
# (Since GitHub only accept UTC timezone, convert the trigger time to 00:00 UTC)
- cron: '0 0 * * 1'
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if this Wednesday is the first one of the month
env:
GH_TOKEN: ${{ github.token }}
run: |
upcomingWed=$(date -d "next Wednesday" +%-d)
if [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then
echo "Triggered manually, don't check if the week contains the first Wednesday of a month. Continue the process."
elif (( upcomingWed > 7 )); then
echo "Triggered automatically, the week does not contain the first Wednesday of a month. End the process."
gh run cancel ${{ github.run_id }}
sleep infinity
else
echo "Triggered automatically, the week contains the first Wednesday of a month. Continue the process."
fi
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22'
- name: Install Codex CLI
run: |
sudo npm install -g @openai/[email protected]
- name: Install dependencies
run: |
sudo apt install git
- name: Generate PR summary issue
id: gen_issue
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
CODEX_QUIET_MODE: 1
GH_TOKEN: ${{ github.token }}
run: |
echo "Update the version number for releasing the latest version of Quark." > ISSUE_BODY.md
echo "In this version, the following changes will be included." >> ISSUE_BODY.md
echo " " >> ISSUE_BODY.md
sudo chmod o+x ISSUE_BODY.md
git fetch --tags
lastVersionNum="$(git tag --sort=-creatordate | head -n 1)"
monthOfLastRelease=$(echo $lastVersionNum | awk -F. '{print $2}')
codex -a auto-edit -q \
"""
Follow the following instructions:
1. Read the git commit messages from the month $monthOfLastRelease of this year.
2. Show all the commit messages after the “Update version information to $lastVersionNum” commit.
3. Show the #Numbers in those commit messages in Step 2.
4. Append the #Numbers in Step 3. after the content of ISSUE_BODY.md [with the format - #Number (e.g. - #761), one number a line]
"""
versionNum="v$(date -d "next Wednesday" +'%y.%-m.1')"
monthOfThisRelease=$(echo $versionNum | awk -F. '{print $2}')
if [ $monthOfThisRelease = $monthOfLastRelease ]; then
versionNum="$(echo $lastVersionNum | awk -F. -v OFS=. '{$NF+=1; print}')"
fi
issueNum=$(gh issue create \
--title "Prepare to release version $versionNum" \
--body-file ISSUE_BODY.md | awk -F"/" '{print $NF}')
echo "version=$versionNum" >> $GITHUB_OUTPUT
echo "issue=$issueNum" >> $GITHUB_OUTPUT
- name: Update changelog for Kali package
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
CODEX_QUIET_MODE: 1
run: |
dateToday="$(TZ=Asia/Taipei date +'%a, %d %b %Y %H:%M:%S %z')"
versionNum=${{ steps.gen_issue.outputs.version }}
codex -a auto-edit -q \
"""
Follow the instructions below to update debian/changelog for $versionNum.
In debian/changelog, you are going to append a new section, and describe what the new
merged PRs since the last release do. Here are the instructions:
1. First, identify the Pull Requests since the last release by reading ISSUE_BODY.md.
2. Next, for each Pull Request, choose a proper tag for it.
A tag could be from [Rule Enhancement/Document Enhancement/New Feature/Bug Fix/Dependency Update/etc.]
You can reference the previous changelog to see if the tag matches the Pull Requests.
Or, if the Pull Requests are something we have never done before, try to give them a proper name.
3. Then, combine those descriptions that are similar. For example,
Optimize the Quark Script documents for CWE-328, CWE-338, and CWE-489. (#754, #756, and #757)
4. Use the following template and make sure it follows the Debian changelog format.
(Also, use Zin Wong <[email protected]> as the maintainer's info):
quark-engine (YY.M.X-0kali1) kali-dev; urgency=medium
* TAG
- DESCRIPTION
-- Zin Wong <[email protected]> RELEASE_TIME_TODAY
, where YY.M.X should align with $versionNum and RELEASE_TIME_TODAY is $dateToday. For example,
quark-engine (25.1.1-0kali1) kali-dev; urgency=medium
* Document Enhancement
- Optimize the Quark Script documents for CWE-94, CWE-798, and CWE-921. (#724, #722, and #723)
-- Zin Wong <[email protected]> Tue, 01 Jan 2025 20:00:00 +0800
"""
rm ISSUE_BODY.md
- name: Update version information
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_KEY }}
CODEX_QUIET_MODE: 1
run: |
versionNum=${{ steps.gen_issue.outputs.version }}
codex -a auto-edit -q \
"""
Update version information in the following files for next release $versionNum:
1. debian/control: Standards-Version
2. docs/source/conf.py: release
3. quark/__init__.py: __version__
"""
- name: Commit the changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add debian/control
git add debian/changelog
git add docs/source/conf.py
git add quark/__init__.py
versionNum=${{ steps.gen_issue.outputs.version }}
git commit -m "Update version information for $versionNum" || echo "No changes to commit"
- name: Create pull request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: "update_version_info_${{ steps.gen_issue.outputs.version }}"
title: "Update version information to ${{ steps.gen_issue.outputs.version }}"
body: "Resolves #${{ steps.gen_issue.outputs.issue }}."