-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add workflow for manual npm package publishing RISDEV-4537 (#6)
- Loading branch information
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
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 }} |