Merge pull request #18 from mars167/copilot/update-gitignore-logic #25
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 | |
| skip_github_release: | |
| description: "Skip GitHub Release creation (useful for npm retry)" | |
| 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" | |
| # Check if GitHub Release already exists | |
| - name: Check existing GitHub Release | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| id: check_release | |
| run: | | |
| if gh release view "${{ env.RELEASE_TAG }}" &>/dev/null; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| echo "::notice::GitHub Release ${{ env.RELEASE_TAG }} already exists, skipping creation" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload Tarball Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: npm-tarball | |
| path: ${{ steps.pack.outputs.tarball }} | |
| overwrite: true | |
| - name: Create GitHub Release (attach tarball) | |
| if: ${{ env.RELEASE_TAG != '' && steps.check_release.outputs.exists != 'true' && inputs.skip_github_release != true }} | |
| 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 }} | |
| continue-on-error: true | |
| id: publish_github | |
| run: | | |
| npm pkg set name="@${{ github.repository_owner }}/git-ai" | |
| npm publish --access public 2>&1 | tee publish_output.txt || true | |
| if grep -q "You cannot publish over the previously published versions" publish_output.txt; then | |
| echo "::notice::Version already exists on GitHub Packages, skipping" | |
| echo "skipped=true" >> "$GITHUB_OUTPUT" | |
| elif grep -q "Cannot publish over existing version" publish_output.txt; then | |
| echo "::notice::Version already exists on GitHub Packages (E409), skipping" | |
| echo "skipped=true" >> "$GITHUB_OUTPUT" | |
| elif grep -q "^\+ @${{ github.repository_owner }}/git-ai@" publish_output.txt; then | |
| echo "::notice::Successfully published to GitHub Packages" | |
| echo "skipped=false" >> "$GITHUB_OUTPUT" | |
| elif grep -q "npm error 40[13]" publish_output.txt; then | |
| echo "::warning::GitHub Packages publish failed with auth error, continuing to npmjs.org" | |
| echo "skipped=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "::error::Failed to publish to GitHub Packages" | |
| cat publish_output.txt | |
| exit 1 | |
| fi | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Restore package name for npmjs | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| run: | | |
| npm pkg set name="@mars167/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" | |
| scope: "@mars167" | |
| - name: Publish to npmjs.org | |
| if: ${{ env.RELEASE_TAG != '' }} | |
| id: publish_npm | |
| run: | | |
| npm publish --access public --provenance 2>&1 | tee publish_output.txt || true | |
| if grep -q "You cannot publish over the previously published versions" publish_output.txt; then | |
| echo "::notice::Version already exists on npmjs.org, skipping" | |
| echo "skipped=true" >> "$GITHUB_OUTPUT" | |
| elif grep -q "^\+ @mars167/git-ai@" publish_output.txt; then | |
| echo "::notice::Successfully published to npmjs.org" | |
| echo "skipped=false" >> "$GITHUB_OUTPUT" | |
| elif grep -q "npm error" publish_output.txt; then | |
| echo "::error::Failed to publish to npmjs.org" | |
| cat publish_output.txt | |
| exit 1 | |
| else | |
| echo "::warning::Unexpected npm publish output, check logs" | |
| cat publish_output.txt | |
| echo "skipped=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| 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 "### GitHub Release:" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.check_release.outputs.exists }}" == "true" ] || [ "${{ inputs.skip_github_release }}" == "true" ]; then | |
| echo "- [x] Already exists (skipped)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- [x] Created" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Published to:" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.publish_github.outputs.skipped }}" == "true" ]; then | |
| echo "- [x] GitHub Packages: \`@${{ github.repository_owner }}/git-ai\` (already exists)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- [x] GitHub Packages: \`@${{ github.repository_owner }}/git-ai\`" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [ "${{ steps.publish_npm.outputs.skipped }}" == "true" ]; then | |
| echo "- [x] npmjs.org: \`@mars167/git-ai\` (already exists)" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- [x] npmjs.org: \`@mars167/git-ai\`" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Install:" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY | |
| echo "npm install -g @mars167/git-ai" >> $GITHUB_STEP_SUMMARY | |
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY |