Skip to content

min

min #8

Workflow file for this run

name: Publish release on push tag
on:
push:
tags: 'v*'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
package-name: [react-snapshot-context]
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- id: read-package-json
name: Read package.json
run: echo version=`cat package.json | jq -r '.version'` >> $GITHUB_OUTPUT
- name: Propagate versions
run: |
cd packages/${{ matrix.package-name }}
npm version --no-git-tag-version ${{ steps.read-package-json.outputs.version }}
- run: npm clean-install
- run: npm run build --if-present
- name: Run npm pack
run: |
cd packages/${{ matrix.package-name }}
npm pack
- name: Upload changelog artifact
uses: actions/[email protected]
with:
name: changelog
path: CHANGELOG.md
- name: Upload tarball artifact
uses: actions/[email protected]
with:
name: tarball
path: packages/${{ matrix.package-name }}/*.tgz
- name: Build pages
run: |
cd packages/pages
npm install ../${{ matrix.package-name }}/*.tgz
npm run build
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v1
with:
path: packages/pages/public
draft-release:
needs:
- build
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Download changelog artifact
uses: actions/[email protected]
with:
name: changelog
- name: Download tarball artifact
uses: actions/[email protected]
with:
name: tarball
- name: Draft a new release
run: gh release create ${{ github.ref_name }} ./*.tgz --draft --notes-file ./CHANGELOG.md --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
publish-package:
environment: production
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- name: Download tarball artifact
uses: actions/[email protected]
with:
name: tarball
- id: read-package-json
name: Read package.json
run: |
echo package-name=`tar --extract --file=\`ls ./*.tgz\` --to-stdout package/package.json | jq -r .name` >> $GITHUB_OUTPUT
echo version=`tar --extract --file=\`ls ./*.tgz\` --to-stdout package/package.json | jq -r .version` >> $GITHUB_OUTPUT
- if: ${{ contains(steps.read-package-json.outputs.version, '-') }}
name: Check version number
run: |
echo ::error::Cannot publish prerelease version ${{ steps.read-package-json.outputs.version }}
exit 1
- run: npm publish `ls ./*.tgz`
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Summarize job
run: echo NPM package published to https://npmjs.com/package/${{ steps.read-package-json.outputs.package-name }}/v/${{ steps.read-package-json.outputs.version }}. >> $GITHUB_STEP_SUMMARY
publish-release:
needs:
- draft-release
- publish-package
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Publish release
run: gh release edit ${{ github.ref_name }} --draft=false --repo ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
- name: Summarize job
run: echo GitHub release created at https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}. >> $GITHUB_STEP_SUMMARY
create-bump-pull-request:
continue-on-error: true
environment: production
needs:
- publish-package
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Configure user profile
run: |
git config user.email "${{ format('@{0}', github.actor) }}"
git config user.name "${{ format('@{0}', github.actor) }}"
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
- id: bump-version
run: |
npm version prepatch --no-git-tag-version
echo version=`cat package.json | jq -r .version` >> $GITHUB_OUTPUT
- name: Create branch
id: create-branch
run: |
BRANCH_NAME=bump-${{ steps.bump-version.outputs.version }}
echo branch-name=$BRANCH_NAME >> $GITHUB_OUTPUT
git checkout -b $BRANCH_NAME
git add --all
git commit --message "Bump to ${{ steps.bump-version.outputs.version }}"
git push --set-upstream origin $BRANCH_NAME
- continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GH_TOKEN_CREATE_PULL_REQUEST }}
id: create-pull-request
name: Create pull request
run: |
PULL_REQUEST_NUMBER=`gh api repos/${{ github.repository }}/pulls --field base=main --field head=${{ steps.create-branch.outputs.branch-name }} --field title="Bump to ${{ steps.bump-version.outputs.version }}" | jq -r '.number'`
gh api repos/${{ github.repository }}/issues/$PULL_REQUEST_NUMBER/assignees --field assignees[]=${{ github.actor }}
echo url=https://github.com/${{ github.repository }}/pull/$PULL_REQUEST_NUMBER >> $GITHUB_OUTPUT
- name: Summarize job
run: |
if [ "${{ steps.create-pull-request.outputs.url }}" = "" ]; then
echo "Branch created at [bump-${{ steps.bump-version.outputs.version }}](https://github.com/${{ github.repository }}/compare/main...${{ steps.create-branch.outputs.branch-name }})" >> $GITHUB_STEP_SUMMARY
else
echo Pull request created at ${{ steps.create-pull-request.outputs.url }}. >> $GITHUB_STEP_SUMMARY
fi
publish-pages:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
permissions:
pages: write
id-token: write
runs-on: ubuntu-latest
steps:
- id: deployment
name: Deploy to GitHub Pages
uses: actions/deploy-pages@v2