Publish dev version #88
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: Publish dev version | |
on: | |
workflow_dispatch: | |
inputs: | |
trigger-manual: | |
description: 'Manually trigger the workflow' | |
jobs: | |
publish-dev-version: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
package: | |
# List the packages to run here. The matrix will run one job for each package parallelly. | |
- api-augment | |
- types | |
- config | |
- adapter | |
- sdk | |
steps: | |
- name: 🤘 checkout | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install Yarn v2 | |
run: npm install -g yarn@berry | |
- name: Install dependencies | |
run: yarn install | |
- name: Run build | |
run: yarn build | |
- name: 🔐 Authenticate with NPM | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTOMATION_TOKEN_CHRIS }}" > ~/.npmrc | |
- name: Get the current dev version of packages | |
id: get-current-dev-version | |
run: | | |
# Get the dev tag version | |
tags=$(yarn npm info @oak-network/${{ matrix.package }} --fields dist-tags --json) | |
echo "Tag versions: $tags" | |
current_dev_version=$(echo $tags | jq -r '.["dist-tags"].dev') | |
echo "Dev tag version: $current_dev_version" | |
echo "current_dev_version=$current_dev_version" >> "$GITHUB_ENV" | |
# Get the latest version | |
all_versions=$(yarn npm info @oak-network/${{ matrix.package }} --fields versions --json) | |
echo "All versions: $all_versions" | |
highest_version=$(echo "$all_versions" | jq -r '.versions[]' | sort -V | tail -n1) | |
echo "Highest version: $highest_version" | |
echo "highest_version=$highest_version" >> "$GITHUB_ENV" | |
- name: 🚀 Publish ${{ matrix.package }} package if newer than latest | |
working-directory: ./packages/${{ matrix.package }}/build | |
run: | | |
new_version=$(node -p "require('./package.json').version") | |
echo "New version from local build folder: $new_version" | |
# Debugging: Print the values of $highest_version and $current_dev_version | |
echo "Current Dev Version: $current_dev_version" | |
echo "Highest Version: $highest_version" | |
# Compare the new version with the current dev version and the highest version; If we publish a lower than the highest version, it will be rejected by npm.js. | |
# TODO: I was not able to check if the new version is higher than both the current dev version and the highest version yet, so the check is very simple here. Ideally, we should check if the new version is higher. | |
if [ "$new_version" != "$current_dev_version" ]; then | |
echo "New version $new_version is different from NPM dev tag version $current_dev_version; publishing..." | |
npm publish --tag dev | |
else | |
echo "Skip publish since there’s no higher version number." | |
fi |