Skip to content

Commit

Permalink
Merge pull request #21 from fastly/kats/ci-release
Browse files Browse the repository at this point in the history
Release to npmjs using CI
  • Loading branch information
harmony7 authored Nov 27, 2024
2 parents 9ec70e8 + 34fe432 commit 50999dd
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/ci-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Release CI
on:
push:
tags:
# This looks like a regex, but it's actually a filter pattern
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
- 'v*.*.*'
- 'v*.*.*-*'

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: "Checkout code"
uses: actions/checkout@v4

- name: Validate SemVer tag
run: |
TAG="${GITHUB_REF_NAME#refs/tags/}"
if [[ ! "$TAG" =~ ^v[0-9]+(\.[0-9]+){2}(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "::error::Invalid tag: $TAG. Must follow SemVer syntax (e.g., v1.2.3, v1.2.3-alpha)."
exit 1
fi
shell: bash

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'

- name: Extract prerelease tag if present
id: extract-tag
run: |
TAG="${GITHUB_REF_NAME#v}" # Remove the "v" prefix
if [[ "$TAG" == *-* ]]; then
PRERELEASE=${TAG#*-} # Remove everything before the dash
PRERELEASE=${PRERELEASE%%.*} # Remove everything after the first period
else
PRERELEASE="latest"
fi
echo "dist-tag=$PRERELEASE" >> $GITHUB_ENV
- name: Install npm dependencies
run: npm install

- name: Publish to npmjs.org
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "Publishing to npmjs.org using dist-tag: $dist-tag"
npm publish --access=public --tag "$dist-tag"

0 comments on commit 50999dd

Please sign in to comment.