Skip to content

Release

Release #5

Workflow file for this run

name: Release
on:
schedule:
- cron: '0 0 1 * *' # 每月的第一天 00:00 UTC
workflow_dispatch: # 允許手動觸發工作流
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
create-git-branch-release:
runs-on: ubuntu-latest
permissions:
contents: write
env:
RELEASE_BRANCH: release
outputs:
branch: ${{ env.RELEASE_BRANCH }}
steps:
- uses: actions/checkout@v4
- name: Create release branch
run: git checkout -B $RELEASE_BRANCH
- name: Remove submodule (if exists)
env:
SUBMODULE_PATH: Submodule/github/rest-api-description
run: |
if [ -d "$SUBMODULE_PATH" ]; then
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git submodule deinit -f $SUBMODULE_PATH || true
git rm -f $SUBMODULE_PATH || true
rm -rf .git/modules/$SUBMODULE_PATH || true
git commit -m "Remove submodule"
else
echo "Submodule not found, skipping removal."
fi
- name: Push release branch
run: git push --force --set-upstream origin $RELEASE_BRANCH
create-github-release:
needs: create-git-branch-release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Get latest version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_VERSION=$(gh release view --repo ${{ github.repository }} --json tagName --jq .tagName)
echo "Latest release version: $LATEST_VERSION"
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
- name: Bump patch version
run: |
# Extract version numbers
VERSION=${LATEST_VERSION#v}
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
# Bump the patch number
PATCH=$((PATCH+1))
# Form new version
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
- name: Create new GitHub release
env:
GIT_REF: ${{ needs.create-git-branch-release.outputs.branch }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create $NEW_VERSION \
--repo ${{ github.repository }} \
--generate-notes \
--target "$GIT_REF"