using git tags #15
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: Release | |
on: | |
push: | |
branches: | |
- main # Trigger only on pushes to the main branch | |
workflow_dispatch: # Allows manually triggering the workflow for testing or urgent releases | |
concurrency: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
release: | |
if: github.repository == 'Ingvarstep/GLiNER.js' | |
permissions: | |
contents: write # Required to create the release | |
actions: read # For checking token permissions | |
issues: write # For creating an issue | |
name: Create GitHub Release and Publish to npm | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Set up Node.js | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
# Set up pnpm | |
- name: Set up pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 6.0.2 | |
# Install dependencies | |
- name: Install dependencies | |
run: pnpm install | |
# Check for pending changesets before proceeding with the release | |
- name: Check for changesets | |
id: check_changesets | |
run: | | |
if pnpm changeset status | grep -q "No unreleased changesets"; then | |
echo "No unreleased changesets found. Skipping version bump and release." | |
exit 0 | |
fi | |
continue-on-error: false # If no changesets are found, this step will stop the workflow | |
# Run Changesets to version the packages and apply changelogs | |
- name: Run Changesets version | |
if: steps.check_changesets.outcome == 'success' | |
run: pnpm changeset version | |
# Commit the version bump and changelog updates (if applicable) | |
- name: Commit version bump | |
if: steps.check_changesets.outcome == 'success' | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add . | |
git commit -m "Version bump and changelog update" | |
git push | |
# Create a new Git tag based on the version from package.json | |
- name: Create Tag | |
if: steps.check_changesets.outcome == 'success' | |
run: | | |
VERSION=$(cat package.json | jq -r '.version') | |
git tag v$VERSION | |
git push origin v$VERSION | |
# Build the package (after version bump) | |
- name: Build the package | |
if: steps.check_changesets.outcome == 'success' | |
run: pnpm run build # Ensure you have a build script in your package.json | |
# Create a release archive (zip) | |
- name: Create a release archive | |
if: steps.check_changesets.outcome == 'success' | |
run: zip -r package-release.zip dist package.json src README.md CHANGELOG.md | |
# Create GitHub Release and Upload Release Asset using softprops/action-gh-release | |
- name: Create GitHub Release and Upload Asset | |
if: steps.check_changesets.outcome == 'success' | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ github.ref_name }} # Use the tag created in the previous step | |
files: ./package-release.zip # Path to the asset to be uploaded | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication | |
# Publish to npm (optional) | |
# Uncomment this section if you're ready to publish automatically | |
# - name: Publish to npm | |
# if: steps.check_changesets.outcome == 'success' | |
# run: pnpm publish | |
# env: | |
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |