|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + version: |
| 10 | + description: "Version to release (e.g., v1.2.3)" |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + packages: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + release: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup Node.js |
| 29 | + uses: actions/setup-node@v4 |
| 30 | + with: |
| 31 | + node-version: "20" |
| 32 | + cache: "yarn" |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: yarn install --frozen-lockfile |
| 36 | + |
| 37 | + - name: Run tests |
| 38 | + run: yarn test |
| 39 | + |
| 40 | + - name: Build and package |
| 41 | + run: | |
| 42 | + yarn build |
| 43 | + yarn package |
| 44 | +
|
| 45 | + - name: Get version from tag |
| 46 | + id: get_version |
| 47 | + run: | |
| 48 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 49 | + VERSION="${{ github.event.inputs.version }}" |
| 50 | + else |
| 51 | + VERSION=${GITHUB_REF#refs/tags/} |
| 52 | + fi |
| 53 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 54 | + echo "major_version=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + - name: Update major version tag |
| 57 | + run: | |
| 58 | + MAJOR_VERSION=${{ steps.get_version.outputs.major_version }} |
| 59 | + git config --local user.email "[email protected]" |
| 60 | + git config --local user.name "GitHub Action" |
| 61 | + git tag -fa $MAJOR_VERSION -m "Update $MAJOR_VERSION tag" |
| 62 | + git push origin $MAJOR_VERSION --force |
| 63 | +
|
| 64 | + - name: Update release branch |
| 65 | + run: | |
| 66 | + git config --local user.email "[email protected]" |
| 67 | + git config --local user.name "GitHub Action" |
| 68 | + git checkout -B release |
| 69 | + git push origin release --force |
| 70 | +
|
| 71 | + - name: Create GitHub Release |
| 72 | + uses: softprops/action-gh-release@v1 |
| 73 | + with: |
| 74 | + tag_name: ${{ steps.get_version.outputs.version }} |
| 75 | + name: Release ${{ steps.get_version.outputs.version }} |
| 76 | + draft: false |
| 77 | + prerelease: false |
| 78 | + generate_release_notes: true |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments