Skip to content

Migrate commands to skills #154

Migrate commands to skills

Migrate commands to skills #154

Workflow file for this run

name: Publish Package
on:
release:
types: [created, edited] # Trigger on release creation or edit
pull_request: # Trigger on merge to main
types: [closed]
branches: [main] # Trigger on push to tags
workflow_dispatch:
jobs:
prepare-version:
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.extract-version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
clean: true
- name: Extract version from tag
id: extract-version
if: github.event_name == 'release' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
run: |
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
else
# check for new git tag
if git rev-parse "v${{ github.event.release.tag_name }}" >/dev/null 2>&1; then
VERSION=${{ github.event.release.tag_name }}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
else
echo "Not a tag event, aborting"
exit 0
fi
fi
- name: Check if package.json version matches tag
if: steps.extract-version.outputs.version != ''
run: |
# configure git user
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# check if package.json version matches tag
if [[ "$(jq -r '.version' package.json)" != "$VERSION" ]]; then
echo "Package.json version does not match tag, updating version"
npm version ${{ steps.extract-version.outputs.version }} --no-git-tag-version
git add package.json package-lock.json
git commit -m "chore: Update package version to ${{ steps.extract-version.outputs.version }} [skip ci]"
else
echo "Package.json version matches tag, skipping version update"
fi
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
needs: prepare-version
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
scope: '@usrrname'
- run: npm ci
- name: Publish to NPM
run: |
echo "Publishing version ${{ needs.prepare-version.outputs.version }} to NPM registry"
npm config set registry https://registry.npmjs.org --scope=@usrrname
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
publish-gpr:
needs: prepare-version
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://npm.pkg.github.com/
scope: '@usrrname'
- run: npm ci
- name: Publish to GitHub Packages
run: |
echo "Publishing version ${{ needs.prepare-version.outputs.version }} to GitHub Packages"
npm config set registry https://npm.pkg.github.com/ --scope=@usrrname
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}