Build & Release to NPM #27
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: Build & Release to NPM | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
draft_release: | |
permissions: | |
contents: write | |
id-token: write | |
name: Create Draft Release | |
runs-on: ubuntu-latest | |
outputs: | |
release_id: ${{ steps.create_release.outputs.id }} | |
release_version: ${{ steps.tag.outputs.new_tag }} | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
semver_commit_hash: ${{ steps.semver_commit.outputs.commit_hash }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: main | |
- name: Bump version and push tag | |
id: tag | |
uses: mathieudutour/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Bump package.json version | |
id: npm-version | |
uses: reedyuk/npm-version@master | |
with: | |
version: ${{ steps.tag.outputs.new_version }} | |
- name: Commit semver changes to repo | |
id: semver_commit | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
branch: main | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.github_token }} | |
with: | |
tag_name: ${{ steps.tag.outputs.new_tag }} | |
release_name: ${{ steps.tag.outputs.new_tag }} | |
body: ${{ steps.tag.outputs.changelog }} | |
draft: true | |
prerelease: false | |
npm_deploy: | |
needs: [draft_release] | |
name: Deploy package to NPM | |
runs-on: ubuntu-latest | |
env: | |
npm_publish_token: ${{ secrets.NPM_PUBLISH_TOKEN }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ needs.draft_release.outputs.semver_commit_hash }} | |
- name: Set up NodeJS | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm install | |
- name: Build TypeScript into JavaScript | |
run: npm run build:code | |
- name: Build app | |
uses: JS-DevTools/npm-publish@v3 | |
with: | |
token: ${{ secrets.npm_publish_token }} | |
access: "public" | |
make_release: | |
needs: [draft_release, npm_deploy] | |
name: Publish the Draft Release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout GitHub Action | |
uses: actions/checkout@v4 | |
- name: Mark release as published | |
uses: eregon/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
release_id: ${{ needs.draft_release.outputs.release_id }} |