Prepare @ton/cocos-sdk for publication. #9
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: Publish to NPM | |
on: | |
push: | |
tags: | |
# package-major.minor.patch - required | |
# -beta.build - optional | |
- '*-*.*.*' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- id: get-package | |
run: | | |
PACKAGE_NAME=$(echo ${GITHUB_REF#refs/tags/} | cut -d- -f1) | |
ALLOWED_PACKAGES=("phaser" "cocos") | |
if [[ " ${ALLOWED_PACKAGES[@]} " =~ " ${PACKAGE_NAME} " ]]; then | |
echo "::set-output name=package::${PACKAGE_NAME}" | |
echo "::set-output name=version::${GITHUB_REF#refs/tags/}" | |
else | |
echo "Invalid package name ${PACKAGE_NAME}." | |
exit 1 | |
fi | |
shell: bash | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Check version | |
run: | | |
TAG_VERSION=$(echo ${GITHUB_REF#refs/tags/${{ steps.get-package.outputs.package }}-}) | |
PACKAGE_VERSION=$(node -p "require('./packages/${{ steps.get-package.outputs.package }}/package.json').version") | |
if [[ "${TAG_VERSION}" != "${PACKAGE_VERSION}" ]]; then | |
echo "Tag version ${TAG_VERSION} does not match package version ${PACKAGE_VERSION}." | |
exit 1 | |
fi | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build --workspace @ton/${{ steps.get-package.outputs.package }}-sdk | |
- name: Publish | |
run: | | |
cd packages/${{ steps.get-package.outputs.package }} | |
if echo "${{ steps.get-package.outputs.version }}" | grep -q "\-beta"; then | |
npm publish --access=public --tag=beta | |
else | |
npm publish --access=public | |
fi | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |