what #62
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: Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| preflight: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.12.0 | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm install | |
| - name: Verify version is new | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| LATEST_JSON=$(curl -sSL -H "Authorization: Bearer $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" https://api.github.com/repos/GraphStats/Classify/releases/latest || true) | |
| LATEST=$(echo "$LATEST_JSON" | jq -r '.tag_name // empty') | |
| LATEST=${LATEST#v} | |
| echo "package.json version: $VERSION" | |
| echo "latest release tag: ${LATEST:-none}" | |
| if [ -n "$LATEST" ] && [ "$LATEST" = "$VERSION" ]; then | |
| echo "Version $VERSION is already released. Bump version before building." | |
| exit 1 | |
| fi | |
| - name: Lint | |
| run: npm run lint | |
| - name: Typecheck | |
| run: npm run typecheck | |
| build: | |
| needs: preflight | |
| strategy: | |
| matrix: | |
| include: | |
| - os: windows-latest | |
| platform: windows | |
| arch: x64 | |
| - os: macos-15-intel | |
| platform: mac | |
| arch: x64 | |
| - os: macos-latest | |
| platform: mac | |
| arch: arm64 | |
| - os: ubuntu-latest | |
| platform: linux | |
| arch: x64 | |
| runs-on: ${{ matrix.os }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22.12.0 | |
| cache: 'npm' | |
| - name: Install Dependencies | |
| run: npm install | |
| - name: Build Application (Windows) | |
| if: matrix.platform == 'windows' | |
| run: npm run build:win | |
| - name: Build Application (macOS) | |
| if: matrix.platform == 'mac' | |
| run: npm run build:mac:${{ matrix.arch }} | |
| - name: Rename macOS artifact (Intel) | |
| if: matrix.platform == 'mac' && matrix.arch == 'x64' | |
| run: | | |
| for f in dist-exe/*.dmg; do | |
| mv "$f" "${f//Mac.x64/Mac.Intel}" | |
| done | |
| for f in dist-exe/*.blockmap; do | |
| mv "$f" "${f//Mac.x64/Mac.Intel}" | |
| done | |
| python - <<'PY' | |
| from pathlib import Path | |
| for path in Path("dist-exe").glob("latest-mac*.yml"): | |
| text = path.read_text() | |
| path.write_text(text.replace("Mac.x64", "Mac.Intel")) | |
| PY | |
| - name: Rename macOS artifact (ARM) | |
| if: matrix.platform == 'mac' && matrix.arch == 'arm64' | |
| run: | | |
| for f in dist-exe/*.dmg; do | |
| mv "$f" "${f//Mac.arm64/Mac.ARM}" | |
| done | |
| for f in dist-exe/*.blockmap; do | |
| mv "$f" "${f//Mac.arm64/Mac.ARM}" | |
| done | |
| if [ -f dist-exe/latest-mac.yml ]; then | |
| mv dist-exe/latest-mac.yml dist-exe/latest-mac-arm64.yml | |
| fi | |
| python - <<'PY' | |
| from pathlib import Path | |
| for path in Path("dist-exe").glob("latest-mac*.yml"): | |
| text = path.read_text() | |
| path.write_text(text.replace("Mac.arm64", "Mac.ARM")) | |
| PY | |
| - name: Build Application (Linux) | |
| if: matrix.platform == 'linux' | |
| run: npm run build:linux | |
| - name: Upload Windows Artifact | |
| if: matrix.platform == 'windows' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-windows-x64 | |
| path: | | |
| dist-exe/*.exe | |
| dist-exe/*.yml | |
| dist-exe/*.blockmap | |
| - name: Upload macOS Artifact | |
| if: matrix.platform == 'mac' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-macos-${{ matrix.arch }} | |
| path: | | |
| dist-exe/*.dmg | |
| dist-exe/*.yml | |
| dist-exe/*.blockmap | |
| - name: Upload Linux Artifact | |
| if: matrix.platform == 'linux' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-linux-${{ matrix.arch }} | |
| path: | | |
| dist-exe/*.AppImage | |
| dist-exe/*.yml | |
| dist-exe/*.blockmap | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Get Version from package.json | |
| id: package-version | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create or update release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.package-version.outputs.version }}" | |
| TAG="v$VERSION" | |
| if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then | |
| echo "Release $TAG already exists." | |
| else | |
| gh release create "$TAG" \ | |
| --repo "$GITHUB_REPOSITORY" \ | |
| --title "$TAG" \ | |
| --notes "${{ github.event.head_commit.message }}" | |
| fi | |
| - name: Upload release assets | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="${{ steps.package-version.outputs.version }}" | |
| TAG="v$VERSION" | |
| shopt -s nullglob globstar | |
| find artifacts \( -name 'builder-debug.yml' -o -name 'builder-effective-config.yml' \) -delete | |
| files=(artifacts/**/*.exe artifacts/**/*.dmg artifacts/**/*.AppImage artifacts/**/*.yml artifacts/**/*.blockmap) | |
| if [ ${#files[@]} -eq 0 ]; then | |
| echo "No release artifacts found to upload." | |
| exit 1 | |
| fi | |
| gh release upload "$TAG" "${files[@]}" --repo "$GITHUB_REPOSITORY" --clobber |