Publish libraries #6
This file contains hidden or 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 libraries | |
| on: | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - "v**" | |
| permissions: | |
| contents: read | |
| env: | |
| IS_UPSTREAM: ${{ github.repository_owner == 'Sofie-Automation' }} | |
| NPM_PACKAGE_SCOPE: ${{ vars.NPM_PACKAGE_SCOPE }} # In the form of nrkno, without the @ | |
| NPM_PACKAGE_PREFIX: ${{ vars.NPM_PACKAGE_PREFIX }} # Set to anything to prefix the published package names with "sofie-". eg in combination with NPM_PACKAGE_SCOPE this will turn @sofie-automation/shared-lib into @nrkno/sofie-shared-lib | |
| jobs: | |
| check-publish: | |
| name: Check if publish is possible | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| outputs: | |
| can-publish: ${{ steps.check.outputs.can-publish }} | |
| npm-scope: ${{ steps.check.outputs.npm-scope }} | |
| steps: | |
| - name: Check release is possible | |
| id: check | |
| run: | | |
| if [ "${{ env.IS_UPSTREAM }}" = "true" ]; then | |
| echo "Upstream repo, publishing unscoped" >> $GITHUB_STEP_SUMMARY | |
| echo "can-publish=1" >> $GITHUB_OUTPUT | |
| echo "npm-scope=" >> $GITHUB_OUTPUT | |
| elif [ "${{ env.NPM_PACKAGE_SCOPE }}" = "" ]; then | |
| echo "No NPM_PACKAGE_SCOPE set, not publishing" >> $GITHUB_STEP_SUMMARY | |
| echo "can-publish=0" >> $GITHUB_OUTPUT | |
| echo "npm-scope=" >> $GITHUB_OUTPUT | |
| else | |
| echo "Downstream repo, publishing scoped to \`@${{ env.NPM_PACKAGE_SCOPE }}\`" >> $GITHUB_STEP_SUMMARY | |
| echo "can-publish=1" >> $GITHUB_OUTPUT | |
| echo "npm-scope=${{ env.NPM_PACKAGE_SCOPE }}" >> $GITHUB_OUTPUT | |
| fi | |
| lint-packages: | |
| name: Lint Lib | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| timeout-minutes: 15 | |
| needs: check-publish | |
| if: ${{ needs.check-publish.outputs.can-publish == '1' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package-name: | |
| - blueprints-integration | |
| - server-core-integration | |
| - shared-lib | |
| - live-status-gateway-api | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: Prepare Environment | |
| run: | | |
| corepack enable | |
| cd packages | |
| yarn install | |
| yarn lerna run --scope \*\*/${{ matrix.package-name }} --include-dependencies --stream build | |
| env: | |
| CI: true | |
| - name: Run typecheck and linter | |
| run: | | |
| cd packages/${{ matrix.package-name }} | |
| yarn lint | |
| env: | |
| CI: true | |
| test-packages: | |
| name: Test Lib | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: check-publish | |
| if: ${{ needs.check-publish.outputs.can-publish == '1' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package-name: | |
| - blueprints-integration | |
| - server-core-integration | |
| - shared-lib | |
| # - live-status-gateway-api # no tests yet | |
| - openapi | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Prepare Environment | |
| run: | | |
| corepack enable | |
| cd packages | |
| yarn install | |
| yarn lerna run --scope \*\*/${{ matrix.package-name }} --include-dependencies --stream build | |
| env: | |
| CI: true | |
| - name: Run tests | |
| run: | | |
| cd packages/${{ matrix.package-name }} | |
| yarn unit | |
| env: | |
| CI: true | |
| prepare-publish: | |
| name: Prepare for publish | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: check-publish | |
| if: ${{ needs.check-publish.outputs.can-publish == '1' }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| persist-credentials: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: Prepare Environment | |
| run: | | |
| corepack enable | |
| cd packages | |
| yarn install | |
| env: | |
| CI: true | |
| - name: Bump version | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| run: | | |
| cd packages | |
| COMMIT_TIMESTAMP=$(git log -1 --pretty=format:%ct HEAD) | |
| COMMIT_DATE=$(date -d @$COMMIT_TIMESTAMP +%Y%m%d-%H%M%S) | |
| GIT_HASH=$(git rev-parse --short HEAD) | |
| PRERELEASE_TAG=nightly-$(echo "${{ github.ref_name }}" | sed -r 's/[^a-z0-9]+/-/gi') | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "superflytvab" | |
| yarn set-version-and-commit prerelease --preid $PRERELEASE_TAG-$COMMIT_DATE-$GIT_HASH | |
| env: | |
| CI: true | |
| - name: Build | |
| run: | | |
| cd packages | |
| yarn build | |
| env: | |
| CI: true | |
| - name: Build OpenAPI client library | |
| run: | | |
| cd packages/openapi | |
| yarn build | |
| env: | |
| CI: true | |
| - name: Modify dependencies to use npm packages | |
| run: | | |
| node scripts/prepublish.js "${{ github.repository }}" "${{ env.NPM_PACKAGE_SCOPE }}" ${{ env.NPM_PACKAGE_PREFIX }} | |
| cd packages | |
| yarn install --no-immutable | |
| - name: Upload release artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: publish-dist | |
| path: | | |
| packages/*/dist | |
| packages/*/package.json | |
| packages/package.json | |
| packages/yarn.lock | |
| package.json | |
| retention-days: 1 | |
| if-no-files-found: error | |
| publish: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| needs: | |
| - prepare-publish | |
| - test-packages | |
| permissions: | |
| contents: write | |
| id-token: write # scoped for as short as possible, as this gives write access to npm | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Use Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: '.node-version' | |
| - name: Download release artifact | |
| uses: actions/download-artifact@v6 | |
| with: | |
| name: publish-dist | |
| - name: Publish to NPM | |
| id: publish-npm | |
| run: | | |
| # Commit any changes, to make lerna happy that the tree isn't dirty | |
| git config --global user.email "[email protected]" | |
| git config --global user.name "superflytvab" | |
| git add . | |
| git commit -m "chore: temp commit" --no-verify --allow-empty | |
| # If an npm token is provided, use it (for simpler setup in forks) | |
| if [ "${{ secrets.NPM_TOKEN }}" != "" ]; then | |
| echo "Using provided NPM token" | |
| echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc | |
| else | |
| echo "No NPM token provided, using trusted publishing" | |
| fi | |
| corepack enable | |
| # make dependencies of `determine-npm-tag` available | |
| yarn install --mode=skip-build | |
| cd packages | |
| yarn install | |
| NPM_TAG=nightly | |
| if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then | |
| PACKAGE_NAME=$(node -p "require('./shared-lib/package.json').name") | |
| PUBLISHED_VERSION=$(yarn npm info --json $PACKAGE_NAME | jq -c '.version' -r) | |
| THIS_VERSION=$(node -p "require('./lerna.json').version") | |
| NPM_TAG=$(node ../scripts/determine-npm-tag.js "$PUBLISHED_VERSION" "$THIS_VERSION") | |
| fi | |
| yarn lerna publish from-package --tag-version-prefix='' --dist-tag $NPM_TAG --yes | |
| NEW_VERSION=$(node -p "require('./lerna.json').version") | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "**Published:** $NEW_VERSION as $NPM_TAG" >> $GITHUB_STEP_SUMMARY | |
| env: | |
| NPM_CONFIG_PROVENANCE: true | |
| CI: true |