Merge pull request #11 from mars167/feature/skills-and-npm-publish #15
Workflow file for this run
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 | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Tag name to release (e.g. v1.2.3). If empty, skip release/publish steps." | |
| required: false | |
| type: string | |
| npm_only: | |
| description: "Only publish to npm (skip GitHub Packages)" | |
| required: false | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: write | |
| packages: write | |
| id-token: write | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| env: | |
| RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || inputs.tag }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Checkout input tag | |
| if: ${{ inputs.tag != '' && github.ref_type != 'tag' }} | |
| run: git checkout "${{ inputs.tag }}" | |
| - name: Setup Node (build/test) | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: "npm" | |
| cache-dependency-path: package-lock.json | |
| - name: Install | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Test | |
| run: npm test | |
| - name: Sync version from Tag | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| run: | | |
| VERSION=${RELEASE_TAG#v} | |
| echo "Syncing version to $VERSION" | |
| npm version $VERSION --no-git-tag-version --allow-same-version | |
| - name: Pack | |
| id: pack | |
| run: | | |
| TARBALL="$(npm pack --silent)" | |
| echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT" | |
| - name: Upload Tarball Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: npm-tarball | |
| path: ${{ steps.pack.outputs.tarball }} | |
| - name: Create GitHub Release (attach tarball) | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.RELEASE_TAG }} | |
| files: ${{ steps.pack.outputs.tarball }} | |
| generate_release_notes: true | |
| - name: Setup Node (GitHub Packages) | |
| if: ${{ env.RELEASE_TAG != '' && inputs.npm_only != true }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| registry-url: "https://npm.pkg.github.com" | |
| scope: "@${{ github.repository_owner }}" | |
| - name: Publish to GitHub Packages | |
| if: ${{ env.RELEASE_TAG != '' && inputs.npm_only != true }} | |
| run: | | |
| npm pkg set name="@${{ github.repository_owner }}/git-ai" | |
| npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Restore package name for npmjs | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| run: | | |
| npm pkg set name="git-ai" | |
| - name: Setup Node (npmjs.org) | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Publish to npmjs.org | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| run: | | |
| npm publish --access public --provenance | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish Summary | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| run: | | |
| echo "## Release Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ env.RELEASE_TAG }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Published to:" >> $GITHUB_STEP_SUMMARY | |
| echo "- [x] GitHub Packages: \`@${{ github.repository_owner }}/git-ai\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- [x] npmjs.org: \`git-ai\`" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Install:" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "npm install -g git-ai" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |