Skip to content

Commit

Permalink
add workflow for manual npm package publishing RISDEV-4537 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamo225 authored Aug 13, 2024
1 parent d1ac11d commit ec0d568
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Publish Package to npm

on:
workflow_dispatch:
inputs:
release-type:
description: "Release type (one of): patch, minor, major"
required: true

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: write
id-token: write

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
scope: '@digitalservicebund'
cache: npm

- name: Install Dependencies
run: npm ci

- name: Git configuration
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
- name: Bump Release Version
run: |
echo "NEW_VERSION=$(npm --no-git-tag-version version ${{ github.event.inputs['release-type'] }} -m 'Release %s')" >> $GITHUB_ENV
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
- name: Commit Version Bump
run: |
git add package.json
git commit -m "Release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
- name: Build Project
run: npm run build

- name: Commit Build Output
run: |
git add dist/ -f
git commit -m "Build output for version ${{ env.NEW_VERSION }}"
- name: Push Changes and Tags
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin HEAD --tags
- name: Publish to npm
run: npm publish --provenance --access public
working-directory: dist
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Zip dist folder
run: zip -r pkg.zip dist
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.NEW_VERSION }}
generate_release_notes: true
files: pkg.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit ec0d568

Please sign in to comment.