|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 0 1 * *' # 每月的第一天 00:00 UTC |
| 6 | + workflow_dispatch: # 允許手動觸發工作流 |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: ${{ github.workflow }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + create-git-branch-release: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + branch: ${{ steps.release_branch.outputs.value }} |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v3 # Use the latest stable version |
| 20 | + |
| 21 | + - name: Create release branch |
| 22 | + env: |
| 23 | + RELEASE_BRANCH: release |
| 24 | + id: release_branch |
| 25 | + run: | |
| 26 | + git checkout -B $RELEASE_BRANCH |
| 27 | + echo "value=$RELEASE_BRANCH" >> $GITHUB_OUTPUT |
| 28 | + |
| 29 | + - name: Remove submodule (if exists) |
| 30 | + env: |
| 31 | + SUBMODULE_PATH: Submodule/github/rest-api-description |
| 32 | + run: | |
| 33 | + if [ -d "$SUBMODULE_PATH" ]; then |
| 34 | + git submodule deinit -f $SUBMODULE_PATH || true |
| 35 | + git rm -f $SUBMODULE_PATH || true |
| 36 | + rm -rf .git/modules/$SUBMODULE_PATH || true |
| 37 | + git commit -m "Remove submodule" |
| 38 | + git push |
| 39 | + else |
| 40 | + echo "Submodule not found, skipping removal." |
| 41 | + fi |
| 42 | +
|
| 43 | + create-github-release: |
| 44 | + needs: create-git-branch-release |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Checkout code |
| 48 | + uses: actions/checkout@v3 |
| 49 | + |
| 50 | + - name: Get latest version |
| 51 | + env: |
| 52 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + run: | |
| 54 | + LATEST_VERSION=$(gh release view --repo ${{ github.repository }} --json tagName --jq .tagName) |
| 55 | + echo "Latest release version: $LATEST_VERSION" |
| 56 | + echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV |
| 57 | +
|
| 58 | + - name: Bump patch version |
| 59 | + run: | |
| 60 | + # Extract version numbers |
| 61 | + VERSION=${LATEST_VERSION#v} |
| 62 | + MAJOR=$(echo $VERSION | cut -d. -f1) |
| 63 | + MINOR=$(echo $VERSION | cut -d. -f2) |
| 64 | + PATCH=$(echo $VERSION | cut -d. -f3) |
| 65 | + |
| 66 | + # Bump the patch number |
| 67 | + PATCH=$((PATCH+1)) |
| 68 | + |
| 69 | + # Form new version |
| 70 | + NEW_VERSION="v$MAJOR.$MINOR.$PATCH" |
| 71 | + echo "New version: $NEW_VERSION" |
| 72 | + echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV |
| 73 | +
|
| 74 | + - name: Create new GitHub release |
| 75 | + env: |
| 76 | + GIT_REF: ${{ needs.create-git-branch-release.outputs.branch }} |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + run: | |
| 79 | + gh release create $NEW_VERSION \ |
| 80 | + --repo ${{ github.repository }} \ |
| 81 | + --generate-notes \ |
| 82 | + --target "$GIT_REF" |
0 commit comments