CI #179
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
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| tags: "*.*.*" | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| npm_tag: | |
| description: "npm dist-tag to use (e.g. latest, next, beta, auto to derive from git tag)" | |
| required: false | |
| default: "auto" | |
| dry_run: | |
| description: "Run npm publish in dry-run mode" | |
| type: boolean | |
| default: true | |
| jobs: | |
| test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # Use the oldest currently-available Ubuntu runner for better glibc compatibility. | |
| os: [ | |
| macos-15-intel, # x64 | |
| macos-15, # ARM, | |
| ubuntu-22.04, | |
| ] | |
| # syntax explanation: | |
| # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-additional-values-into-combinations | |
| include: | |
| - os: macos-15-intel | |
| artifact-folder: darwin | |
| - os: macos-15 | |
| artifact-folder: darwinarm64 | |
| - os: ubuntu-22.04 | |
| artifact-folder: linux | |
| runs-on: ${{matrix.os}} | |
| steps: | |
| # normalize line endings in CI checkout | |
| - name: Set git to use LF | |
| run: | | |
| git config --global core.autocrlf false | |
| git config --global core.eol lf | |
| - uses: actions/checkout@v3 | |
| - name: Cache OCaml's opam | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.opam | |
| key: ${{matrix.os}}-rescript-vscode-v4 | |
| - name: Use OCaml | |
| uses: ocaml/setup-ocaml@v3 | |
| with: | |
| ocaml-compiler: 5.3.0 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20.11.0 | |
| - run: npm ci | |
| - run: opam install dune cppo ocamlformat.0.28.1 | |
| # - run: npm run res:build | |
| # These 2 runs (or just the second?) are for when you have opam dependencies. We don't. | |
| # Don't add deps. But if you ever do, un-comment these and add an .opam file. | |
| # - run: opam pin add resgraph.dev . --no-action | |
| # - run: opam install . --deps-only --with-doc --with-test | |
| - name: Build and test | |
| run: opam exec -- make test | |
| - name: Check formatting | |
| if: matrix.os == 'ubuntu-22.04' | |
| run: opam exec -- make checkformat | |
| - name: Verify generated outputs are clean | |
| run: | | |
| status=$(git status --porcelain) | |
| if [ -n "$status" ]; then | |
| echo "Working tree dirty after generation:" | |
| echo "$status" | |
| exit 1 | |
| fi | |
| # Also avoids artifacts upload permission loss: | |
| # https://github.com/actions/upload-artifact/tree/ee69f02b3dfdecd58bb31b4d133da38ba6fe3700#permission-loss | |
| - name: Compress files | |
| run: | | |
| cd bin | |
| mkdir ${{matrix.artifact-folder}} | |
| mv dev/resgraph.exe ${{matrix.artifact-folder}} | |
| tar -cvf binary.tar ${{matrix.artifact-folder}} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{matrix.os}} | |
| path: bin/binary.tar | |
| package: | |
| needs: test | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Use Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| - run: npm ci | |
| - name: Build npm package artifacts | |
| run: npm run build | |
| - name: Verify CLI bundle exists | |
| run: test -f dist/Cli.mjs | |
| - name: Download MacOS x86 binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-15-intel | |
| path: ./bin | |
| - run: tar -xvf binary.tar | |
| working-directory: ./bin | |
| - name: Download MacOS ARM binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-15 | |
| path: ./bin | |
| - run: tar -xvf binary.tar | |
| working-directory: ./bin | |
| - name: Download Linux binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ubuntu-22.04 | |
| path: ./bin | |
| - run: tar -xvf binary.tar | |
| working-directory: ./bin | |
| - name: Cleanup tar file | |
| run: rm binary.tar | |
| working-directory: ./bin | |
| - name: Store short commit SHA for filename | |
| id: vars | |
| env: | |
| COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} | |
| run: echo "::set-output name=sha_short::${COMMIT_SHA:0:7}" | |
| - name: Store tag name | |
| id: tag_name | |
| if: startsWith(github.ref, 'refs/tags/') | |
| run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} | |
| - name: Package release | |
| run: npm pack | |
| - name: Rename package | |
| run: mv resgraph*.tgz resgraph.tgz | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: resgraph.tgz | |
| path: resgraph.tgz | |
| - name: Compute npm tag and dry-run flag | |
| id: npm_publish | |
| run: | | |
| input_tag="${{ github.event.inputs.npm_tag }}" | |
| dry_run="${{ github.event.inputs.dry_run }}" | |
| ref_tag="${GITHUB_REF#refs/tags/}" | |
| if [[ -z "$input_tag" || "$input_tag" == "auto" ]]; then | |
| if [[ "$ref_tag" != "$GITHUB_REF" && "$ref_tag" == *"-"* ]]; then | |
| tag="next" | |
| else | |
| tag="latest" | |
| fi | |
| else | |
| tag="$input_tag" | |
| fi | |
| if [[ "$dry_run" == "" ]]; then dry_run="false"; fi | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| echo "dry_run=$dry_run" >> "$GITHUB_OUTPUT" | |
| echo "Using npm tag '$tag' (dry-run: $dry_run)." | |
| - name: Publish to npm | |
| if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' | |
| env: | |
| NPM_TAG: ${{ steps.npm_publish.outputs.tag }} | |
| DRY_RUN: ${{ steps.npm_publish.outputs.dry_run }} | |
| run: | | |
| args="--tag $NPM_TAG" | |
| if [[ "$DRY_RUN" == "true" ]]; then | |
| echo "Running npm publish in dry-run mode" | |
| args="$args --dry-run" | |
| fi | |
| npm publish $args |