Add github packahe publish #21
This file contains hidden or 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: CI/CD Pipeline | ||
on: | ||
release: | ||
types: | ||
- published | ||
jobs: | ||
build-test-deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- name: Set up Bun | ||
uses: oven-sh/setup-bun@v2 | ||
- name: Update version in package.json to match release tag | ||
run: | | ||
RELEASE_TAG=${GITHUB_REF#refs/tags/} | ||
jq --arg tag "$RELEASE_TAG" '.version = $tag' package.json > package.json.tmp && mv package.json.tmp package.json | ||
git config user.name "github-actions" | ||
git config user.email "[email protected]" | ||
git commit -am "Update version to match release tag $RELEASE_TAG" | ||
git push | ||
- name: Install dependencies | ||
run: bun i | ||
- name: Build the project | ||
run: bun run build | ||
- name: Log in to npm | ||
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | ||
- name: Publish to npm | ||
if: startsWith(github.ref, 'refs/tags/') | ||
run: npm publish --access public | ||
- name: Publish to GitHub Packages | ||
if: startsWith(github.ref, 'refs/tags/') | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "@${{ github.repository_owner }}:registry=https://npm.pkg.github.com" >> ~/.npmrc | ||
npm publish --registry=https://npm.pkg.github.com | ||
- name: Upload Build Artifacts | ||
uses: actions/upload-release-asset@v1 | ||
with: | ||
upload_url: ${{ github.event.release.upload_url }} | ||
asset_path: ./dist | ||
asset_name: build.zip | ||
asset_content_type: application/zip |