Release package patch #40
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: Release package | |
run-name: Release package ${{ github.event.inputs.release-type }}${{ github.event.inputs.dry-run == 'true' && ' (dry-run)' || '' }} | |
on: | |
workflow_dispatch: | |
inputs: | |
release-type: | |
description: "Release type (one of): patch, minor, major, prepatch, preminor, premajor, prerelease" | |
required: true | |
dry-run: | |
description: "Perform a dry run" | |
required: false | |
type: boolean | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: write | |
strategy: | |
matrix: | |
node-version: [16.x] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
clean: true | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Git configuration | |
run: | | |
git config --global user.email "902348742+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions" | |
- name: Install Dependencies | |
run: | | |
yarn install | |
yarn global add @babel/cli @babel/core | |
- name: Change release version | |
run: npm version ${{ env.RELEASE_TYPE }} | |
env: | |
RELEASE_TYPE: ${{ github.event.inputs.release-type }} | |
- name: Build the package | |
run: | | |
rm -rf dist/* | |
NODE_ENV=production yarn babel src/lib --out-dir dist --copy-files --source-maps both --ignore *.stories.js,__tests__,spec.js,test.js,__snapshots__ | |
githash=$(git rev-parse --short HEAD) | |
version=$(npm pkg get version | tr -d '"') | |
echo $githash > dist/githash | |
echo $version > dist/version | |
echo "const version='$version'; const hash='$githash'; export {version, hash};" > dist/meta.js | |
cp -rf package.json dist | |
- name: Determine Publish Command | |
id: determine-publish | |
run: echo "PUBLISH_COMMAND=$( [ '${{ github.event.inputs.dry-run }}' == 'true' ] && echo 'npm publish --dry-run' || echo 'npm publish')" >> $GITHUB_ENV | |
- name: .npmrc | |
run: | | |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISHING_TOKEN }}" > dist/.npmrc | |
echo ".npmrc" > dist/.npmignore | |
echo "_stories/" >> dist/.npmignore | |
- name: Publish the package | |
id: publish | |
run: | | |
cd dist | |
$PUBLISH_COMMAND | |
- name: Push changes to repository | |
if: ${{ github.event.inputs.dry-run == 'false' }} | |
run: git push origin dev && git push --tags |