This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
Workflow/test line compare deployment #45
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
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Node.js Package | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- run: yarn ci | |
check-version: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
outputs: | |
version-updated: ${{ steps.compare-versions.outputs.version-updated }} | |
steps: | |
- name: Checkout main branch at commit before merge | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.base.sha }} | |
- name: Get package version from main branch before merge | |
id: pre-merge-version | |
run: | | |
PRE_MERGE_VERSION=$(node -p "require('./package.json').version") | |
echo "::set-output name=pre_merge_version::$PRE_MERGE_VERSION" | |
- name: Checkout main branch at commit after merge | |
uses: actions/checkout@v3 | |
with: | |
ref: 'main' | |
- name: Get package version from main branch after merge | |
id: post-merge-version | |
run: | | |
POST_MERGE_VERSION=$(node -p "require('./package.json').version") | |
echo "::set-output name=post_merge_version::$POST_MERGE_VERSION" | |
- name: Compare versions | |
id: compare-versions | |
run: | | |
if [[ "${{ steps.pre-merge-version.outputs.pre_merge_version }}" != "${{ steps.post-merge-version.outputs.post_merge_version }}" ]]; then | |
echo "::set-output name=version-updated::true" | |
else | |
echo "::set-output name=version-updated::false" | |
fi | |
publish-npm: | |
needs: [build, check-version] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
registry-url: https://registry.npmjs.org/ | |
- run: yarn ci | |
- run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | |