Merge pull request #16 from 343dev/improvement/internal-stuff #10
This file contains 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: Publish Package to npmjs | |
on: | |
push: | |
branches: [main] | |
jobs: | |
publish_to_npm: | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write # “andymckay/cancel-action” requires “write” access to the “actions” permission | |
id-token: write # Provenance generation in GitHub Actions requires “write” access to the “id-token” permission | |
steps: | |
- | |
name: Checkout repository | |
uses: actions/checkout@v4 | |
- | |
name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18.17.0' | |
registry-url: 'https://registry.npmjs.org' | |
- | |
name: Check if package version has changed | |
id: check | |
run: | | |
LATEST_VERSION=$(npm view . version) | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
if [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then | |
echo "Version changed from $LATEST_VERSION to $CURRENT_VERSION" | |
echo "VERSION_CHANGED=true" >> $GITHUB_OUTPUT | |
else | |
echo "Version unchanged" | |
echo "VERSION_CHANGED=false" >> $GITHUB_OUTPUT | |
fi | |
- | |
name: Cancelling | |
uses: andymckay/[email protected] | |
if: ${{ steps.check.outputs.VERSION_CHANGED == 'false' }} | |
- | |
name: Install dependencies | |
if: ${{ steps.check.outputs.VERSION_CHANGED == 'true' }} | |
run: npm ci | |
- | |
name: Publish to npm | |
if: ${{ steps.check.outputs.VERSION_CHANGED == 'true' }} | |
run: npm publish --provenance --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |