ci: fix release ci (#6) #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Draft | |
| on: | |
| push: | |
| branches: [ main ] | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| verify: | |
| name: Lint and Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: npm | |
| - name: Install deps | |
| run: npm ci | |
| - name: Lint | |
| run: npm run lint --if-present | |
| - name: Build | |
| run: npm run build | |
| releaseDraft: | |
| name: Release draft | |
| needs: [ verify ] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: npm | |
| - name: Compute version from package.json | |
| id: ver | |
| run: | | |
| VERSION="v$(node -p "require('./package.json').version")" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Remove old release drafts | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| gh api repos/{owner}/{repo}/releases \ | |
| --jq '.[] | select(.draft == true) | .id' \ | |
| | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} || true | |
| - name: Prepare release notes from CHANGELOG | |
| run: | | |
| if [ -f CHANGELOG.md ]; then | |
| awk '/^## \[Unreleased\]/{flag=1;next}/^## \[/{flag=0}flag' CHANGELOG.md | sed '/^$/d' > RELEASE_NOTES.txt | |
| fi | |
| if [ ! -s RELEASE_NOTES.txt ]; then | |
| echo "Maintenance release." > RELEASE_NOTES.txt | |
| fi | |
| - name: Create draft release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.ver.outputs.version }}" | |
| gh release create "$VERSION" --draft --title "$VERSION" --notes-file RELEASE_NOTES.txt || true |