Skip to content

Merge pull request #50 from ProgramingIsTheFuture/new_features #408

Merge pull request #50 from ProgramingIsTheFuture/new_features

Merge pull request #50 from ProgramingIsTheFuture/new_features #408

Workflow file for this run

name: CI
on: [push]
jobs:
build:
name: Built and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [
ubuntu-latest,
macos-latest,
# windows-latest https://github.com/ocaml/dune/issues/11645
]
ocaml-compiler:
- 5.2.1
steps:
- uses: actions/checkout@v4
- name: Use Node.js
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: true
opam-disable-sandboxing: true
- name: Install deps
run: make install
- name: Install npm deps
run: make npm-install
- name: Pin some deps
run: make pin
- name: Build
run: make build-prod
- name: Run tests
run: make test
- name: Web build
if: ${{ matrix.os == 'ubuntu-latest' }}
run: make web-build
- name: Deploy to prod
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
working-directory: ./website
env:
SITE_ID: ${{ secrets.SITE_ID }}
AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run:
npx netlify deploy --site $SITE_ID --auth $AUTH_TOKEN --prod --dir=../dist
- name: Deploy preview
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name == 'pull_request' }}
working-directory: ./website
env:
SITE_ID: ${{ secrets.SITE_ID }}
AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run:
npx netlify deploy --site $SITE_ID --auth $AUTH_TOKEN --dir=../dist
- name: Upload artifacts for ${{ matrix.os }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-artifact
path: _build/default/bin/bin.exe
- name: Upload JavaScript artifacts for NPM
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v4
with:
name: query-json-js
path: _build/default/js/Js.bc.js
publish:
needs: build
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Download JavaScript artifact
uses: actions/download-artifact@v4
with:
name: query-json-js
path: _release/query-json-js
- name: Download linux artifacts
uses: actions/download-artifact@v4
with:
name: ubuntu-latest-artifact
path: _release/platform-linux-x64
- name: Download macOS artifacts
uses: actions/download-artifact@v4
with:
name: macos-latest-artifact
path: _release/platform-darwin-x64
# - name: Download windows artifacts
# uses: actions/download-artifact@v4
# with:
# name: windows-latest-artifact
# path: _release/platform-windows-x64
- name: Debug downloaded artifacts
run: ls -R _release
- name: Allow execution of query-json
run: chmod +x _release/platform-linux-x64/bin.exe
- name: Get version
id: currentVersion
run: |
CURRENT=$(_release/platform-linux-x64/bin.exe --version);
echo "version=$CURRENT" >> "$GITHUB_OUTPUT"
- name: Generate NPM package and release
run: node scripts/make-npm-release.js ${{ steps.currentVersion.outputs.version }}
- name: Create archives for Github release
run: |
cd _release/platform-darwin-x64
mv bin.exe query-json
zip -r ../../query-json-darwin-x64.zip .
cd ../..
cd _release/platform-linux-x64
mv bin.exe query-json
zip -r ../../query-json-linux-x64.zip .
cd ../..
# cd _release/platform-windows-x64
# mv bin.exe query-json
# zip -r ../../query-json-windows-x64.zip .
# cd ../..
- name: Check if should be published
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
id: newVersion
run: |
REMOTE=$(npm show -s @davesnx/query-json version);
[[ "$REMOTE" != "${{ steps.currentVersion.outputs.version }}" ]] && echo "shouldPublish=true" >> "$GITHUB_OUTPUT" || echo "shouldPublish=false" >> "$GITHUB_OUTPUT"
- name: Publish
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.newVersion.outputs.shouldPublish == 'true' }}
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm config set scope "@davesnx"
npm publish --access public
working-directory: ./_release
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Print short SHA
id: sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Publish Prerelease
if: ${{ github.event_name != 'push' && github.ref != 'refs/heads/main' }}
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm config set scope "@davesnx"
npm version prerelease -preid ${{ steps.sha.outputs.sha_short }} -no-git-tag-version
npm publish --tag=dev --access public
working-directory: ./_release
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
- name: Create Github release
if: ${{ steps.newVersion.outputs.shouldPublish == 'true' }}
id: create_release
uses: ncipollo/release-action@v1.16.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ steps.currentVersion.outputs.version }}
draft: false
prerelease: false
- name: Upload query-json-darwin-x64.zip to Github release
if: ${{ steps.newVersion.outputs.shouldPublish == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-darwin-x64.zip
asset_name: query-json-darwin-x64.zip
asset_content_type: application/zip
- name: Upload query-json-linux-x64.zip to Github release
if: ${{ steps.newVersion.outputs.shouldPublish == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./query-json-linux-x64.zip
asset_name: query-json-linux-x64.zip
asset_content_type: application/zip
# - name: Upload query-json-windows-x64.zip to Github release
# if: ${{ steps.newVersion.outputs.shouldPublish == 'true' }}
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./query-json-windows-x64.zip
# asset_name: query-json-windows-x64.zip
# asset_content_type: application/zip