chore: release main (#35) #35
Workflow file for this run
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-surface-base-v[0-9]+.[0-9]+.[0-9]+*' | |
| - 'companion-surface-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: 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-surface/base" | |
| PACKAGE_PATH="packages/companion-surface-base" | |
| else | |
| PACKAGE_NAME="@companion-surface/host" | |
| PACKAGE_PATH="packages/companion-surface-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-surface-base-v* ]]; then | |
| PACKAGE_NAME="@companion-surface/base" | |
| PACKAGE_SHORT_NAME="base" | |
| PACKAGE_PATH="packages/companion-surface-base" | |
| elif [[ "$TAG" == companion-surface-host-v* ]]; then | |
| PACKAGE_NAME="@companion-surface/host" | |
| PACKAGE_SHORT_NAME="host" | |
| PACKAGE_PATH="packages/companion-surface-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 | |
| 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 |