Build & Release #10
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: Build & Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' # Full release (npm + Electron) | |
| - 'npm-v*' # npm only | |
| - 'electron-v*' # Electron only | |
| workflow_dispatch: | |
| inputs: | |
| publish_npm: | |
| description: 'Publish to npm' | |
| required: true | |
| type: boolean | |
| default: false | |
| npm_version: | |
| description: 'npm version override (leave empty to use server/package.json)' | |
| required: false | |
| type: string | |
| build_electron: | |
| description: 'Build Electron installer & GitHub Release' | |
| required: true | |
| type: boolean | |
| default: false | |
| electron_version: | |
| description: 'Electron version override (leave empty to use package.json)' | |
| required: false | |
| type: string | |
| jobs: | |
| # ── Determine what to build ──────────────────────────────── | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| do_npm: ${{ steps.resolve.outputs.do_npm }} | |
| do_electron: ${{ steps.resolve.outputs.do_electron }} | |
| npm_version: ${{ steps.resolve.outputs.npm_version }} | |
| electron_version: ${{ steps.resolve.outputs.electron_version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: resolve | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.event_name }}" == "push" ]]; then | |
| TAG="${GITHUB_REF_NAME}" | |
| if [[ "$TAG" == npm-v* ]]; then | |
| echo "do_npm=true" >> $GITHUB_OUTPUT | |
| echo "do_electron=false" >> $GITHUB_OUTPUT | |
| echo "npm_version=${TAG#npm-v}" >> $GITHUB_OUTPUT | |
| elif [[ "$TAG" == electron-v* ]]; then | |
| echo "do_npm=false" >> $GITHUB_OUTPUT | |
| echo "do_electron=true" >> $GITHUB_OUTPUT | |
| echo "electron_version=${TAG#electron-v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "do_npm=true" >> $GITHUB_OUTPUT | |
| echo "do_electron=true" >> $GITHUB_OUTPUT | |
| echo "npm_version=$(node -p "require('./server/package.json').version")" >> $GITHUB_OUTPUT | |
| echo "electron_version=${TAG#v}" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "do_npm=${{ inputs.publish_npm }}" >> $GITHUB_OUTPUT | |
| echo "do_electron=${{ inputs.build_electron }}" >> $GITHUB_OUTPUT | |
| if [[ -n "${{ inputs.npm_version }}" ]]; then | |
| echo "npm_version=${{ inputs.npm_version }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "npm_version=$(node -p "require('./server/package.json').version")" >> $GITHUB_OUTPUT | |
| fi | |
| if [[ -n "${{ inputs.electron_version }}" ]]; then | |
| echo "electron_version=${{ inputs.electron_version }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "electron_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| # ── Publish to npm (Trusted Publisher via OIDC) ──────────── | |
| publish-npm: | |
| needs: prepare | |
| if: needs.prepare.outputs.do_npm == 'true' | |
| runs-on: ubuntu-latest | |
| environment: npm-publish | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| registry-url: https://registry.npmjs.org | |
| - run: npm ci | |
| - name: Build server | |
| run: npm run build -w server | |
| - name: Publish to npm | |
| working-directory: server | |
| run: | | |
| npm version "${{ needs.prepare.outputs.npm_version }}" --no-git-tag-version --allow-same-version | |
| npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| # ── Build Electron + GitHub Release ──────────────────────── | |
| publish-electron: | |
| needs: prepare | |
| if: needs.prepare.outputs.do_electron == 'true' | |
| runs-on: windows-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - run: npm ci | |
| - name: Build application | |
| run: | | |
| npm run build | |
| npx tsc -p electron/tsconfig.json | |
| - name: Sync Electron version | |
| shell: bash | |
| run: npm version "${{ needs.prepare.outputs.electron_version }}" --no-git-tag-version --allow-same-version | |
| - name: Package Electron app | |
| run: npx electron-builder --win --publish never | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: electron-v${{ needs.prepare.outputs.electron_version }} | |
| name: ChatCrystal v${{ needs.prepare.outputs.electron_version }} | |
| draft: false | |
| prerelease: ${{ contains(needs.prepare.outputs.electron_version, '-') }} | |
| generate_release_notes: true | |
| files: | | |
| release/*.exe | |
| release/*.yml | |
| release/*.yaml |