Skip to content

Add repository field to package.json (fixes E422 provenance on publish) #5

Add repository field to package.json (fixes E422 provenance on publish)

Add repository field to package.json (fixes E422 provenance on publish) #5

Workflow file for this run

name: flipdishbytes.api-client-javascript.publish
on:
pull_request:
push:
branches:
- master
permissions:
id-token: write
contents: read
jobs:
build-and-publish:
concurrency:
group: npm-publish-${{ github.ref }}
cancel-in-progress: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v4
with:
node-version: 24
- name: Install dependencies
run: npm install
- name: Build package
run: npm run build
- name: Get current version from npm
id: current_version
run: |
CURRENT_VERSION=$(npm view @flipdish/api-client-javascript version 2>/dev/null)
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" = "undefined" ]; then
echo "::error::npm view returned no version for @flipdish/api-client-javascript - registry lookup failed or package missing"
exit 1
fi
echo "Current version from npm: $CURRENT_VERSION"
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: new_version
run: |
CURRENT_VERSION=${{ steps.current_version.outputs.version }}
IFS='.' read -r major minor patch <<< "$CURRENT_VERSION"
NEW_VERSION="$major.$minor.$((patch + 1))"
echo "NEW_VERSION: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Install moreutils
run: |
sudo apt-get install -qy moreutils
- name: Update version in package.json
run: |
jq --arg version "${{ steps.new_version.outputs.version }}" '.version = $version' package.json | sponge package.json
echo "Updated package version to $(node -p "require('./package.json').version")"
- name: Dry run publish to npm
if: github.event_name == 'pull_request'
run: |
# Run npm publish dry-run and capture output
output=$(npm publish --access public --dry-run 2>&1)
echo "$output"
# Check for real npm errors ("npm error" / "npm ERR!"), not error-named files
# (this package legitimately contains files like ValidationErrorResult.js)
if echo "$output" | grep -E "^npm error|^npm ERR!" > /dev/null; then
echo "Dry run failed"
exit 1
fi
shell: bash
- name: Publish to npm
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
npm -v
npm publish --access public