Skip to content

ppx_spice publish

ppx_spice publish #55

Workflow file for this run

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: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: src
strategy:
matrix:
os: [ubuntu-latest]
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.os }}
uses: actions/upload-artifact@master
with:
name: ${{ matrix.os }}
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 artifacts
if: success()
uses: actions/download-artifact@master
with:
name: ubuntu-latest
path: binaries/linux
- 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/ppx.exe ppx-linux.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.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.exe
ppx-osx-x64.exe
ppx-osx-arm64.exe
ppx-windows.exe