Manually Release & Publish Package #24
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: Manually Release & Publish Package | |
on: | |
workflow_dispatch: | |
inputs: | |
skip-release: | |
description: 'Skip Release Job' | |
required: true | |
default: 'false' | |
type: choice | |
options: | |
- 'false' | |
- 'true' | |
skip-publish-gpr: | |
description: 'Skip publish Github Job' | |
required: true | |
default: 'false' | |
type: choice | |
options: | |
- 'false' | |
- 'true' | |
# push: | |
# branches: | |
# - main | |
# paths: | |
# - CHANGELOG.md | |
# pull_request: | |
# branches: | |
# - main | |
# paths: | |
# - CHANGELOG.md | |
jobs: | |
release: | |
if: ${{ github.event.inputs.skip-release == 'false' }} | |
name: Create release package | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout to code | |
uses: actions/checkout@v4 | |
- name: install Node js Version 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
- name: Retrieve Release Version | |
run: echo "PV=$(node version.js)" >> $GITHUB_ENV | |
- run: cat change-log | |
- name: Retrieve Release Body | |
run: | | |
{ | |
echo 'PB<<EOF' | |
cat change-log | |
echo EOF | |
} >> $GITHUB_ENV | |
- run: echo ${{env.PV}} | |
- name: Create Github Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{env.PV}} | |
release_name: Release v${{env.PV}} | |
body: ${{env.PB}} | |
publish-gpr: | |
needs: release | |
if: ${{always() && (needs.release.result == 'success' || needs.release.result == 'skipped') && github.event.inputs.skip-publish-gpr == 'false'}} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
# Setup .npmrc file to publish to GitHub Packages | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://npm.pkg.github.com' | |
# Defaults to the user or organization that owns the workflow file | |
scope: '@mohammadrezaeicode' | |
- run: npm set @mohammadrezaeicode:registry=https://npm.pkg.github.com/ | |
- run: npm login --scope=@mohammadrezaeicode --registry=https://npm.pkg.github.com | |
- run: npm adduser | |
- run: npm ci | |
- run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish: | |
name: Publish to NPM | |
needs: publish-gpr | |
if: ${{always() && (needs.publish-gpr.result == 'success' || needs.publish-gpr.result == 'skipped') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout to code | |
uses: actions/checkout@v4 | |
- name: install Node js Version 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://registry.npmjs.org' | |
- run: npm ci | |
- name: publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |