Manually publish to NPM - Apply changeset in the workflow. #8
Workflow file for this run
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: Manually publish to NPM - Apply changeset in the workflow. | |
# publish only when package json has changed - assuming version upgrade | |
on: | |
workflow_dispatch: | |
jobs: | |
publish: | |
if: github.event.repository.owner.login == 'react18-tools' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmjs.org | |
- run: npm i -g [email protected] && pnpm i | |
name: Install dependencies | |
# fail and not publish if any of the unit tests are failing | |
- name: Test | |
run: pnpm test | |
- name: clean up working directory | |
run: git status && git clean -f -d && git status | |
- name: Setup Git and push back to the repo | |
run: | # todo - configure to run for branch for which it is triggered | |
git config --global user.name "mayank1513" | |
git config --global user.email "[email protected]" | |
git fetch | |
git checkout ${{ github.ref_name }} | |
- name: Grab old package version | |
id: oldv | |
run: v=$(node -p -e "require('./lib/package.json').version") && echo "v=$v" >> $GITHUB_OUTPUT | |
- name: Apply changesets | |
run: yarn changeset version | |
- name: Grab package version after applying changesets | |
id: v | |
run: v=$(node -p -e "require('./lib/package.json').version") && echo "v=$v" >> $GITHUB_OUTPUT | |
- name: Validate - allow only patch changes from release branches. Major and minor changes allowed only from main branch | |
# if: github.ref != format('refs/heads/{0}', github.event.repository.default_branch) | |
if: github.ref_name != github.event.repository.default_branch | |
run: node ./scripts/should-publish.js | |
env: | |
oldv: ${{ steps.oldv.v }} | |
v: ${{ steps.v.v }} | |
# - name: Copy Readme file | |
# run: cp ../README.md . # todo: uncomment this line while rebranding | |
- name: Push the changes back to the branch | |
run: git add . && git commit -m "📃 Apply changesets and update CHANGELOG" && git push origin ${{ github.ref_name }} | |
- name: Create release and publish to NPM | |
run: pnpm build && npm publish --provenance --access public | |
working-directory: ./lib | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.event.repository.owner.login }} | |
REPO: ${{ github.event.repository.name }} | |
- name: Craete GitHub Release | |
if: github.ref_name == github.event.repository.default_branch | |
run: | | |
v=$(node -p -e "require('./package.json').version") | |
gh release create $v --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release $v" | |
working-directory: ./lib | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Craete GitHub Release Without setting latest if published from other branch | |
if: github.ref_name != github.event.repository.default_branch | |
run: | | |
v=$(node -p -e "require('./package.json').version") | |
gh release create $v --generate-notes -n "$(sed '1,/^## /d;/^## /,$d' CHANGELOG.md)" --title "Release $v" | |
working-directory: ./lib | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |