This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
feat: updating workflow & bump version #58
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@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- run: yarn ci | |
check-version: | |
runs-on: ubuntu-latest | |
if: github.event.pull_request.merged == true | |
outputs: | |
common-version-updated: ${{ steps.compare-versions.outputs.common-version-updated }} | |
csl-version-updated: ${{ steps.compare-versions.outputs.csl-version-updated }} | |
steps: | |
- name: Checkout main branch at commit before merge | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.base.sha }} | |
- name: Get package version from main branch before merge | |
id: pre-merge-version | |
run: | | |
CSL_PRE_MERGE_VERSION=$(node -p "require('./packages/csl/package.json').version") | |
COMMON_PRE_MERGE_VERSION=$(node -p "require('./packages/common/package.json').version") | |
echo "csl_pre_merge_version=$CSL_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT" | |
echo "common_pre_merge_version=$COMMON_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT" | |
- name: Checkout main branch at commit after merge | |
uses: actions/checkout@v4 | |
with: | |
ref: 'main' | |
- name: Get package version from main branch after merge | |
id: post-merge-version | |
run: | | |
CSL_POST_MERGE_VERSION=$(node -p "require('./packages/csl/package.json').version") | |
COMMON_POST_MERGE_VERSION=$(node -p "require('./packages/common/package.json').version") | |
echo "csl_post_merge_version=$CSL_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT" | |
echo "common_post_merge_version=$COMMON_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT" | |
- name: Compare versions | |
id: compare-versions | |
run: | | |
if [[ "${{ steps.pre-merge-version.outputs.csl_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.csl_post_merge_version }}" ]]; then | |
echo "csl-version-updated=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "csl-version-updated=false" >> "$GITHUB_OUTPUT" | |
fi | |
if [[ "${{ steps.pre-merge-version.outputs.common_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.common_post_merge_version }}" ]]; then | |
echo "common-version-updated=true" >> "$GITHUB_OUTPUT" | |
else | |
echo "common-version-updated=false" >> "$GITHUB_OUTPUT" | |
fi | |
publish-common: | |
needs: [build, check-version] | |
if: needs.check-version.outputs.common-version-updated == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmjs.org/ | |
- run: yarn ci | |
- run: cd packages/common && npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | |
publish-csl: | |
needs: [build, check-version] | |
if: needs.check-version.outputs.csl-version-updated == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://registry.npmjs.org/ | |
- run: yarn ci | |
- run: cd packages/csl && npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.npm_token}} |