Release #152
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 | |
| - test | |
| tags: | |
| - v* | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version to publish (without v prefix, e.g. 0.4.1-1)' | |
| required: true | |
| type: string | |
| env: | |
| NODE_VERSION: '22' | |
| jobs: | |
| build: | |
| name: build ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| cargo: cross | |
| binext: "" | |
| platform: linux-x64 | |
| - target: aarch64-unknown-linux-musl | |
| os: ubuntu-latest | |
| cargo: cross | |
| binext: "" | |
| platform: linux-arm64 | |
| - target: x86_64-apple-darwin | |
| os: macos-14 | |
| cargo: cargo | |
| binext: "" | |
| platform: darwin-x64 | |
| - target: aarch64-apple-darwin | |
| os: macos-15 | |
| cargo: cargo | |
| binext: "" | |
| platform: darwin-arm64 | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-2022 | |
| cargo: cargo | |
| binext: .exe | |
| platform: windows-x64 | |
| - target: aarch64-pc-windows-msvc | |
| os: windows-11-arm | |
| cargo: cargo | |
| binext: .exe | |
| platform: windows-arm64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: Swatinem/rust-cache@v2 | |
| with: | |
| cache-on-failure: true | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross | |
| if: matrix.cargo == 'cross' | |
| run: cargo install cross --git https://github.com/cross-rs/cross.git | |
| - name: Build default and opencc binaries | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p platforms/@zhconv/cli-${{ matrix.platform }} | |
| mkdir -p platforms/@zhconv/cli-opencc-${{ matrix.platform }} | |
| # default (MediaWiki) | |
| ${{ matrix.cargo }} build --features bin-build --bin zhconv --release --target ${{ matrix.target }} | |
| cp target/${{ matrix.target }}/release/zhconv${{ matrix.binext }} \ | |
| platforms/@zhconv/cli-${{ matrix.platform }}/zhconv${{ matrix.binext }} | |
| chmod +x platforms/@zhconv/cli-${{ matrix.platform }}/zhconv${{ matrix.binext }} | |
| # opencc (MediaWiki + OpenCC) | |
| ${{ matrix.cargo }} build --features bin-build --features opencc --bin zhconv --release --target ${{ matrix.target }} | |
| cp target/${{ matrix.target }}/release/zhconv${{ matrix.binext }} \ | |
| platforms/@zhconv/cli-opencc-${{ matrix.platform }}/zhconv${{ matrix.binext }} | |
| chmod +x platforms/@zhconv/cli-opencc-${{ matrix.platform }}/zhconv${{ matrix.binext }} | |
| # GitHub Release binaries (kept for backwards compat) | |
| mkdir -p bin | |
| cp target/${{ matrix.target }}/release/zhconv${{ matrix.binext }} "bin/zhconv-${{ matrix.target }}${{ matrix.binext }}" | |
| - name: Generate default platform package.json | |
| shell: bash | |
| env: | |
| node_pkg: "@zhconv/cli-${{ matrix.platform }}" | |
| node_version: ${{ inputs.version || github.ref_name }} | |
| node_ext: ${{ matrix.binext }} | |
| node_os: ${{ matrix.platform == 'linux-x64' && 'linux' || matrix.platform == 'linux-arm64' && 'linux' || startsWith(matrix.platform, 'darwin') && 'darwin' || 'win32' }} | |
| node_cpu: ${{ endsWith(matrix.platform, 'x64') && 'x64' || 'arm64' }} | |
| run: | |
| version="${node_version#v}" | |
| version="$version" node_version="$version" envsubst < npm-cli/package.json.tmpl > platforms/@zhconv/cli-${{ matrix.platform }}/package.json | |
| - name: Generate opencc platform package.json | |
| shell: bash | |
| env: | |
| node_pkg: "@zhconv/cli-opencc-${{ matrix.platform }}" | |
| # Strip leading 'v' from tag (e.g. v0.4.1-1 -> 0.4.1-1) so the version is valid semver | |
| node_version: ${{ inputs.version || github.ref_name }} | |
| node_ext: ${{ matrix.binext }} | |
| node_os: ${{ matrix.platform == 'linux-x64' && 'linux' || matrix.platform == 'linux-arm64' && 'linux' || startsWith(matrix.platform, 'darwin') && 'darwin' || 'win32' }} | |
| node_cpu: ${{ endsWith(matrix.platform, 'x64') && 'x64' || 'arm64' }} | |
| node_libc: musl | |
| run: | | |
| version="${node_version#v}" | |
| version="$version" node_version="$version" envsubst < npm-cli/package.json.tmpl > platforms/@zhconv/cli-opencc-${{ matrix.platform }}/package.json | |
| - name: Upload GitHub Release artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binaries-${{ matrix.target }} | |
| path: bin/ | |
| - name: Upload npm platform artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: npm-platform-${{ matrix.platform }} | |
| path: platforms | |
| release: | |
| runs-on: ubuntu-latest | |
| if: "startsWith(github.ref, 'refs/tags/')" | |
| needs: [build] | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: binaries-* | |
| merge-multiple: true | |
| - name: Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| * | |
| npm-publish: | |
| name: Publish to npm | |
| needs: [build] | |
| if: "inputs.version != '' || startsWith(github.ref, 'refs/tags/')" | |
| runs-on: ubuntu-latest | |
| environment: npm | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: npm-platform-* | |
| path: platforms/ | |
| merge-multiple: true | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Set npm auth token | |
| run: echo "NODE_AUTH_TOKEN=${{ secrets.NPM_API_TOKEN }}" >> $GITHUB_ENV | |
| - name: Assemble meta packages | |
| env: | |
| version: ${{ inputs.version || github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| # Strip leading 'v' from tag (e.g. v0.4.1-1 -> 0.4.1-1) so the version is valid semver | |
| VERSION="${version#v}" | |
| mkdir -p published/@zhconv/cli/bin | |
| cp npm-cli/bin/zhconv.js published/@zhconv/cli/bin/ | |
| cp npm-cli/README.md published/@zhconv/cli/ | |
| cp LICENSE-GPL published/@zhconv/cli/LICENSE | |
| node_version="$VERSION" envsubst < npm-cli/package.json > published/@zhconv/cli/package.json | |
| mkdir -p published/@zhconv/cli-opencc/bin | |
| cp npm-cli/bin/zhconv.js published/@zhconv/cli-opencc/bin/ | |
| cp npm-cli/README.md published/@zhconv/cli-opencc/ | |
| cp LICENSE-GPL published/@zhconv/cli-opencc/LICENSE | |
| node_version="$VERSION" envsubst < npm-cli/package-opencc.json.tmpl > published/@zhconv/cli-opencc/package.json | |
| - name: Publish platform packages (default) | |
| run: | | |
| set -euo pipefail | |
| for dir in platforms/@zhconv/cli-linux-* platforms/@zhconv/cli-darwin-* platforms/@zhconv/cli-windows-*; do | |
| [ -d "$dir" ] || { echo "Skipping $dir - not a directory"; continue; } | |
| echo "Publishing $dir..." | |
| (cd "$dir" && npm publish --access public --tag latest --no-provenance --loglevel verbose) | |
| done | |
| - name: Publish platform packages (opencc) | |
| run: | | |
| set -euo pipefail | |
| for dir in platforms/@zhconv/cli-opencc-*; do | |
| [ -d "$dir" ] || { echo "Skipping $dir - not a directory"; continue; } | |
| echo "Publishing $dir..." | |
| (cd "$dir" && npm publish --access public --tag latest --no-provenance --loglevel verbose) | |
| done | |
| - name: Publish meta packages | |
| run: | | |
| set -euo pipefail | |
| (cd published/@zhconv/cli && npm publish --access public --tag latest --no-provenance --loglevel verbose) | |
| (cd published/@zhconv/cli-opencc && npm publish --access public --tag latest --no-provenance --loglevel verbose) |