name: Publish package on: workflow_dispatch: push: branches: - "master" concurrency: group: publish cancel-in-progress: false jobs: publish: runs-on: ubuntu-latest permissions: contents: write id-token: write packages: write env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v7 with: fetch-depth: 0 - name: Check if the version changed id: version run: | VERSION=$(jq -r .version package.json) BASE_SHA="${{ github.event.before }}" BASE_VERSION="" if [[ -n "$BASE_SHA" && "$BASE_SHA" != "0000000000000000000000000000000000000000" ]]; then BASE_VERSION=$(git show "$BASE_SHA:package.json" 2>/dev/null | jq -r .version || true) fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" if [[ "$VERSION" == "$BASE_VERSION" ]]; then echo "new=false" >> "$GITHUB_OUTPUT" echo "Version $VERSION did not change, nothing to publish." elif gh release view "v$VERSION" > /dev/null 2>&1; then echo "new=false" >> "$GITHUB_OUTPUT" echo "Release v$VERSION already exists, nothing to publish." else echo "new=true" >> "$GITHUB_OUTPUT" fi - uses: actions/setup-node@v7 if: steps.version.outputs.new == 'true' with: node-version: 26.x cache: "npm" - name: Build package if: steps.version.outputs.new == 'true' run: | npm ci npm run build - name: Publish to NPM if: steps.version.outputs.new == 'true' run: npm publish --provenance --access public - name: Publish to GitHub if: steps.version.outputs.new == 'true' run: | NPMRC="$RUNNER_TEMP/.npmrc-github" printf '%s\n' '@igoramadas:registry=https://npm.pkg.github.com' '//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}' > "$NPMRC" npm pkg set name=@igoramadas/bitecache NPM_CONFIG_USERCONFIG="$NPMRC" npm publish --provenance=false env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create release if: steps.version.outputs.new == 'true' run: gh release create "v${{ steps.version.outputs.version }}" --target "${{ github.sha }}" --title "v${{ steps.version.outputs.version }}" --generate-notes