ci: add release action conditionally in publish workflow #5
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
| # https://github.com/orhun/global-chat/blob/main/.github/workflows/cd.yml | ||
| name: Publish Package! | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*.*.*" | ||
| jobs: | ||
| publish-binaries: | ||
| name: Publish binaries | ||
| needs: generate-changelog | ||
| runs-on: ${{ matrix.build.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| build: | ||
| - { | ||
| NAME: linux-x64-glibc, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: x86_64-unknown-linux-gnu, | ||
| NPM_PUBLISH: true | ||
| } | ||
| - { | ||
| NAME: linux-x64-musl, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: x86_64-unknown-linux-musl, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: linux-x86-glibc, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: i686-unknown-linux-gnu, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: linux-x86-musl, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: i686-unknown-linux-musl, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: linux-arm64-glibc, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: aarch64-unknown-linux-gnu, | ||
| NPM_PUBLISH: true | ||
| } | ||
| - { | ||
| NAME: linux-arm64-musl, | ||
| OS: ubuntu-22.04, | ||
| TOOLCHAIN: stable, | ||
| TARGET: aarch64-unknown-linux-musl, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: win32-x64-mingw, | ||
| OS: windows-2022, | ||
| TOOLCHAIN: stable, | ||
| TARGET: x86_64-pc-windows-gnu, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: win32-x64-msvc, | ||
| OS: windows-2022, | ||
| TOOLCHAIN: stable, | ||
| TARGET: x86_64-pc-windows-msvc, | ||
| NPM_PUBLISH: true | ||
| } | ||
| - { | ||
| NAME: win32-x86-msvc, | ||
| OS: windows-2022, | ||
| TOOLCHAIN: stable, | ||
| TARGET: i686-pc-windows-msvc, | ||
| NPM_PUBLISH: false | ||
| } | ||
| - { | ||
| NAME: win32-arm64-msvc, | ||
| OS: windows-2022, | ||
| TOOLCHAIN: stable, | ||
| TARGET: aarch64-pc-windows-msvc, | ||
| NPM_PUBLISH: true | ||
| } | ||
| - { | ||
| NAME: darwin-x64, | ||
| OS: macos-14, | ||
| TOOLCHAIN: stable, | ||
| TARGET: x86_64-apple-darwin, | ||
| NPM_PUBLISH: true | ||
| } | ||
| - { | ||
| NAME: darwin-arm64, | ||
| OS: macos-14, | ||
| TOOLCHAIN: stable, | ||
| TARGET: aarch64-apple-darwin, | ||
| NPM_PUBLISH: true | ||
| } | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Set the release version | ||
| shell: bash | ||
| run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_ENV | ||
| - name: Install dependencies | ||
| shell: bash | ||
| run: | | ||
| if [[ "${{ matrix.build.NAME }}" = *"-musl" ]]; then | ||
| sudo apt-get update | ||
| sudo apt-get install -y --no-install-recommends \ | ||
| --allow-unauthenticated musl-tools | ||
| fi | ||
| - name: Install Rust toolchain | ||
| uses: actions-rs/toolchain@v1 | ||
| with: | ||
| toolchain: ${{ matrix.build.TOOLCHAIN }} | ||
| target: ${{ matrix.build.TARGET }} | ||
| override: true | ||
| - name: Build (linux/macos) | ||
| if: matrix.build.OS != 'windows-2022' | ||
| uses: actions-rs/cargo@v1 | ||
| with: | ||
| use-cross: true | ||
| command: build | ||
| args: --release --locked --target ${{ matrix.build.TARGET }} | ||
| - name: Build (windows) | ||
| if: matrix.build.OS == 'windows-2022' | ||
| uses: actions-rs/cargo@v1 | ||
| with: | ||
| command: build | ||
| args: --release --locked --target ${{ matrix.build.TARGET }} # --no-default-features | ||
| - name: Release action | ||
| if: ${{ !contains(github.ref, '-') }} | ||
| uses: svenstaro/upload-release-action@v2 | ||
| with: | ||
| repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
| file: global-chat-${{ env.RELEASE_VERSION }}-${{ matrix.build.TARGET }}* | ||
| file_glob: true | ||
| overwrite: true | ||
| tag: ${{ github.ref }} | ||
| release_name: "Release v${{ env.RELEASE_VERSION }}" | ||
| body: "${{ needs.generate-changelog.outputs.release_body }}" | ||
| - name: Install node | ||
| if: matrix.build.NPM_PUBLISH == true | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| registry-url: "https://registry.npmjs.org" | ||
| - name: Publish to NPM | ||
| if: matrix.build.NPM_PUBLISH == true | ||
| shell: bash | ||
| run: | | ||
| cd npm | ||
| bin="global-chat" | ||
| node_os=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f1) | ||
| export node_os | ||
| node_arch=$(echo "${{ matrix.build.NAME }}" | cut -d '-' -f2) | ||
| export node_arch | ||
| export version="${{ env.RELEASE_VERSION }}" | ||
| if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then | ||
| export node_pkg="${bin}-windows-${node_arch}" | ||
| else | ||
| export node_pkg="${bin}-${node_os}-${node_arch}" | ||
| fi | ||
| mkdir -p "${node_pkg}/bin" | ||
| envsubst < package.tmpl > "${node_pkg}/package.json" | ||
| if [ "${{ matrix.build.OS }}" = "windows-2022" ]; then | ||
| bin="${bin}.exe" | ||
| fi | ||
| cp "../target/${{ matrix.build.TARGET }}/release/${bin}" "${node_pkg}/bin" | ||
| cp ../README.md "${node_pkg}" | ||
| cd "${node_pkg}" | ||
| npm publish | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| publish-npm: | ||
| name: Publish the base package to NPM | ||
| needs: publish-binaries | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Install node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 18 | ||
| registry-url: "https://registry.npmjs.org" | ||
| - name: Publish the package | ||
| shell: bash | ||
| working-directory: npm | ||
| run: | | ||
| yarn config set npmAuthToken ${NODE_AUTH_TOKEN} | ||
| yarn config set npmPublishRegistry "https://registry.npmjs.org" | ||
| yarn install | ||
| yarn build | ||
| cp ../README.md . | ||
| if [ ${{ contains(github.ref, '-') }} = "true" ]; then | ||
| yarn npm publish --tag rc | ||
| else | ||
| yarn npm publish | ||
| fi | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
| YARN_ENABLE_IMMUTABLE_INSTALLS: false | ||