ppx_spice publish #58
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: ppx_spice publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| ref: | |
| description: "Branch or tag to build and publish from" | |
| required: false | |
| repository: | |
| description: "owner/repo to check out (use fork to test external PRs)" | |
| required: false | |
| npm_tag: | |
| description: "npm dist-tag to publish under (e.g., latest, next)" | |
| required: false | |
| default: latest | |
| env: | |
| TARGET_REF: ${{ github.event.inputs.ref || github.ref }} | |
| TARGET_REPO: ${{ github.event.inputs.repository || github.repository }} | |
| NPM_TAG: ${{ github.event.inputs.npm_tag || 'latest' }} | |
| permissions: | |
| id-token: write # Required for OIDC publish to npm | |
| contents: write # Required for creating GitHub releases | |
| jobs: | |
| build_linux: | |
| name: Linux ${{ matrix.arch }} | |
| runs-on: ${{ matrix.runner }} | |
| defaults: | |
| run: | |
| working-directory: src | |
| strategy: | |
| matrix: | |
| include: | |
| - arch: x64 | |
| runner: ubuntu-latest | |
| artifact: linux-x64 | |
| ocaml-compiler: 4.14.2 | |
| - arch: arm64 | |
| runner: ubuntu-24.04-arm | |
| artifact: linux-arm64 | |
| ocaml-compiler: 4.14.2 | |
| container: | |
| image: ocaml/opam:alpine-3.16-ocaml-4.14 | |
| options: --user root | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: ${{ env.TARGET_REPO }} | |
| ref: ${{ env.TARGET_REF }} | |
| - name: Opam init | |
| run: opam init -a --disable-sandboxing --compiler=4.14.2 | |
| - name: Install deps | |
| run: opam install . --deps-only --with-test | |
| - name: Build | |
| run: opam exec -- dune build --profile static | |
| - name: Copy built PPX file | |
| run: | | |
| mv ./_build/default/bin/bin.exe ppx.exe | |
| - name: (only on release) Upload artifacts ${{ matrix.artifact }} | |
| uses: actions/upload-artifact@master | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: src/ppx.exe | |
| if-no-files-found: error | |
| build_macos_x64: | |
| name: macOS-x64 | |
| runs-on: macos-15 | |
| defaults: | |
| run: | |
| working-directory: src | |
| env: | |
| ocaml-compiler: 4.14.2 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: ${{ env.TARGET_REPO }} | |
| ref: ${{ env.TARGET_REF }} | |
| - name: Use OCaml ${{ env.ocaml-compiler }} | |
| uses: ocaml/setup-ocaml@v2 | |
| with: | |
| ocaml-compiler: ${{ env.ocaml-compiler }} | |
| - name: Install deps | |
| run: opam install . --deps-only --with-test | |
| - name: Build | |
| run: opam exec -- dune build | |
| - name: Copy built PPX file | |
| run: | | |
| mv ./_build/default/bin/bin.exe ppx.exe | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@master | |
| with: | |
| name: macOS-x64 | |
| path: src/ppx.exe | |
| if-no-files-found: error | |
| build_macos_arm64: | |
| name: macOS-arm64 | |
| runs-on: macos-14 | |
| defaults: | |
| run: | |
| working-directory: src | |
| env: | |
| ocaml-compiler: 4.14.2 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: ${{ env.TARGET_REPO }} | |
| ref: ${{ env.TARGET_REF }} | |
| - name: Use OCaml ${{ env.ocaml-compiler }} | |
| uses: ocaml/setup-ocaml@v2 | |
| with: | |
| ocaml-compiler: ${{ env.ocaml-compiler }} | |
| - name: Install deps | |
| run: opam install . --deps-only --with-test | |
| - name: Build | |
| run: opam exec -- dune build | |
| - name: Copy built PPX file | |
| run: | | |
| mv ./_build/default/bin/bin.exe ppx.exe | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@master | |
| with: | |
| name: macOS-arm64 | |
| path: src/ppx.exe | |
| if-no-files-found: error | |
| build_windows: | |
| name: ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| working-directory: src | |
| strategy: | |
| matrix: | |
| os: [windows-latest] | |
| ocaml-compiler: | |
| - 4.14.2 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: ${{ env.TARGET_REPO }} | |
| ref: ${{ env.TARGET_REF }} | |
| - name: Use OCaml ${{ matrix.ocaml-compiler}} | |
| uses: ocaml/setup-ocaml@v2 | |
| with: | |
| ocaml-compiler: ${{ matrix.ocaml-compiler }} | |
| - name: Install deps | |
| run: opam install . --deps-only --with-test | |
| - name: Build | |
| run: opam exec -- dune build | |
| - name: Copy built PPX file | |
| run: | | |
| mv ./_build/default/bin/bin.exe ppx.exe | |
| - name: (only on release) Upload artifacts ${{ matrix.os }} | |
| uses: actions/upload-artifact@master | |
| with: | |
| name: ${{ matrix.os }} | |
| path: src/ppx.exe | |
| if-no-files-found: error | |
| publish: | |
| needs: [build_linux, build_macos_x64, build_macos_arm64, build_windows] | |
| name: (only on release) Publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| with: | |
| repository: ${{ env.TARGET_REPO }} | |
| ref: ${{ env.TARGET_REF }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Update npm for OIDC support | |
| run: npm install -g npm@latest | |
| - name: Download Linux x64 artifacts | |
| if: success() | |
| uses: actions/download-artifact@master | |
| with: | |
| name: linux-x64 | |
| path: binaries/linux-x64 | |
| - name: Download Linux arm64 artifacts | |
| if: success() | |
| uses: actions/download-artifact@master | |
| with: | |
| name: linux-arm64 | |
| path: binaries/linux-arm64 | |
| - name: Download macOS x64 artifacts | |
| if: success() | |
| uses: actions/download-artifact@master | |
| with: | |
| name: macOS-x64 | |
| path: binaries/darwin-x64 | |
| - name: Download macOS arm64 artifacts | |
| if: success() | |
| uses: actions/download-artifact@master | |
| with: | |
| name: macOS-arm64 | |
| path: binaries/darwin-arm64 | |
| - name: Download windows artifacts | |
| if: success() | |
| uses: actions/download-artifact@master | |
| with: | |
| name: windows-latest | |
| path: binaries/windows | |
| - name: Move artifacts | |
| if: success() | |
| run: | | |
| mkdir -p bin | |
| mv binaries/linux-x64/ppx.exe ppx-linux-x64.exe | |
| mv binaries/linux-arm64/ppx.exe ppx-linux-arm64.exe | |
| mv binaries/darwin-x64/ppx.exe ppx-osx-x64.exe | |
| mv binaries/darwin-arm64/ppx.exe ppx-osx-arm64.exe | |
| mv binaries/windows/ppx.exe ppx-windows.exe | |
| - name: Set executable permissions | |
| if: success() | |
| run: chmod +x ppx-linux-x64.exe ppx-linux-arm64.exe ppx-osx-x64.exe ppx-osx-arm64.exe | |
| - name: Pack package | |
| if: success() | |
| run: npm pack | |
| - name: Publish | |
| if: success() | |
| run: | | |
| if [ "${NPM_TAG:-latest}" = "latest" ]; then | |
| npm publish --provenance | |
| else | |
| npm publish --provenance --tag "${NPM_TAG}" | |
| fi | |
| - name: Create GitHub Release | |
| if: success() && startsWith(env.TARGET_REF, 'refs/tags/') || startsWith(env.TARGET_REF, 'v') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.TARGET_REF }} | |
| name: Release ${{ env.TARGET_REF }} | |
| generate_release_notes: true | |
| files: | | |
| ppx-linux-x64.exe | |
| ppx-linux-arm64.exe | |
| ppx-osx-x64.exe | |
| ppx-osx-arm64.exe | |
| ppx-windows.exe |