Publish Release #38
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 Release | |
| on: | |
| push: | |
| tags: | |
| - 'companion-module-base-v[0-9]+.[0-9]+.[0-9]+*' | |
| - 'companion-module-host-v[0-9]+.[0-9]+.[0-9]+*' | |
| workflow_dispatch: | |
| inputs: | |
| package: | |
| description: 'Package to publish' | |
| required: true | |
| type: choice | |
| options: | |
| - base | |
| - host | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| node-version: [22.x] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Prepare Environment | |
| run: | | |
| corepack enable | |
| yarn install | |
| env: | |
| CI: true | |
| - name: Build Packages | |
| run: | | |
| yarn build | |
| env: | |
| CI: true | |
| - name: Run tests | |
| run: | | |
| yarn unit | |
| env: | |
| CI: true | |
| determine-package: | |
| name: Determine which package to publish | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package-name: ${{ steps.determine.outputs.package-name }} | |
| package-short-name: ${{ steps.determine.outputs.package-short-name }} | |
| package-path: ${{ steps.determine.outputs.package-path }} | |
| tag: ${{ steps.determine.outputs.tag }} | |
| prerelease: ${{ steps.determine.outputs.prerelease }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine package from tag or input | |
| id: determine | |
| run: | | |
| # Determine which package we're publishing | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| # Manual dispatch - use input | |
| if [ "${{ github.event.inputs.package }}" = "base" ]; then | |
| PACKAGE_NAME="@companion-module/base" | |
| PACKAGE_SHORT_NAME="base" | |
| PACKAGE_PATH="packages/companion-module-base" | |
| else | |
| PACKAGE_NAME="@companion-module/host" | |
| PACKAGE_SHORT_NAME="host" | |
| PACKAGE_PATH="packages/companion-module-host" | |
| fi | |
| # Determine tag based on branch | |
| if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then | |
| echo "Publishing nightly" | |
| TAG="nightly" | |
| else | |
| echo "Publishing experimental" | |
| TAG="experimental" | |
| fi | |
| # Generate prerelease version suffix | |
| HASH=$(git rev-parse --short HEAD) | |
| TIMESTAMP=$(date +"%Y%m%d-%H%M%S") | |
| PRERELEASE_TAG=nightly-$(echo "${{ github.ref_name }}" | sed -r 's/[^a-z0-9]+/-/gi') | |
| PRERELEASE="${PRERELEASE_TAG}-${TIMESTAMP}-${HASH}" | |
| echo "tag=${TAG}" >> $GITHUB_OUTPUT | |
| echo "prerelease=${PRERELEASE}" >> $GITHUB_OUTPUT | |
| else | |
| # Tag push - parse tag name | |
| TAG="${{ github.ref_name }}" | |
| if [[ "$TAG" == companion-module-base-v* ]]; then | |
| PACKAGE_NAME="@companion-module/base" | |
| PACKAGE_SHORT_NAME="base" | |
| PACKAGE_PATH="packages/companion-module-base" | |
| elif [[ "$TAG" == companion-module-host-v* ]]; then | |
| PACKAGE_NAME="@companion-module/host" | |
| PACKAGE_SHORT_NAME="host" | |
| PACKAGE_PATH="packages/companion-module-host" | |
| else | |
| echo "Unknown tag format: $TAG" | |
| exit 1 | |
| fi | |
| echo "tag=latest" >> $GITHUB_OUTPUT | |
| fi | |
| echo "package-name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT | |
| echo "package-short-name=${PACKAGE_SHORT_NAME}" >> $GITHUB_OUTPUT | |
| echo "package-path=${PACKAGE_PATH}" >> $GITHUB_OUTPUT | |
| prepare: | |
| name: Prepare package | |
| runs-on: ubuntu-latest | |
| needs: determine-package | |
| timeout-minutes: 15 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Use Node.js 22.x | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.x | |
| - name: Enable corepack | |
| run: corepack enable | |
| - name: Prepare build | |
| run: | | |
| yarn install | |
| # Bump to prerelease version if needed | |
| if [ "${{ needs.determine-package.outputs.prerelease }}" != "" ]; then | |
| cd ${{ needs.determine-package.outputs.package-path }} | |
| OLD_VERSION=$(node -p "require('./package.json').version") | |
| yarn version ${OLD_VERSION}-${{ needs.determine-package.outputs.prerelease }} | |
| cd ../.. | |
| fi | |
| yarn build | |
| env: | |
| CI: true | |
| - name: Upload release artifact | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: publish-dist-${{ needs.determine-package.outputs.package-short-name }} | |
| path: | | |
| ${{ needs.determine-package.outputs.package-path }}/dist | |
| ${{ needs.determine-package.outputs.package-path }}/package.json | |
| ${{ needs.determine-package.outputs.package-path }}/README.md | |
| ${{ needs.determine-package.outputs.package-path }}/CHANGELOG.md | |
| ${{ needs.determine-package.outputs.package-path }}/generated | |
| ${{ needs.determine-package.outputs.package-path }}/assets | |
| retention-days: 1 | |
| if-no-files-found: error | |
| - name: Prepare docs | |
| if: ${{ steps.do-publish.outputs.tag == 'latest' }} | |
| run: | | |
| yarn docs:html | |
| - name: Upload docs artifact | |
| if: ${{ steps.do-publish.outputs.tag == 'latest' }} | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| path: docs/ | |
| publish: | |
| name: Publish to NPM | |
| needs: | |
| - prepare | |
| - test | |
| - determine-package | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| 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 22.x | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22.x | |
| - name: Download release artifact | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: publish-dist-${{ needs.determine-package.outputs.package-short-name }} | |
| path: ${{ needs.determine-package.outputs.package-path }} | |
| - name: Publish to NPM | |
| run: | | |
| cd ${{ needs.determine-package.outputs.package-path }} | |
| corepack enable | |
| yarn install | |
| # Publish from the extracted release (build output present) | |
| yarn npm publish --access=public --provenance --tag ${{ needs.determine-package.outputs.tag }} | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "**Published:** ${{ needs.determine-package.outputs.package-name }}@${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY | |
| env: | |
| CI: true | |
| publish-docs: | |
| name: Publish docs | |
| needs: | |
| - prepare | |
| - publish | |
| - determine-package | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pages: write # to deploy to Pages | |
| id-token: write # to verify the deployment originates from an appropriate source | |
| if: ${{ needs.determine-package.outputs.tag == 'latest' }} | |
| # Deploy to the github-pages environment | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |