Let's push and see #340
This file contains 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] | |
jobs: | |
build: | |
name: Built and test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ | |
ubuntu-latest, | |
macos-latest, | |
# windows-latest | |
] | |
ocaml-compiler: | |
- 5.1.0 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js 16.x | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 16.x | |
- name: Restore global node modules cache | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
uses: actions/cache@v1 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-build-${{ env.cache-name }}- | |
${{ runner.os }}-build- | |
${{ runner.os }}- | |
- name: Load opam cache when not Windows | |
if: runner.os != 'Windows' | |
id: opam-cache | |
uses: actions/cache/restore@v3 | |
with: | |
path: ~/.opam | |
key: opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }} | |
- name: Load opam cache when Windows | |
if: runner.os == 'Windows' | |
id: opam-cache-windows | |
uses: actions/cache/restore@v3 | |
with: | |
path: _opam | |
key: opam-${{ matrix.os }}-${{ matrix.ocaml-compiler }}-${{ hashFiles('**.opam') }} | |
- name: Use OCaml ${{ matrix.ocaml-compiler }} | |
uses: ocaml/setup-ocaml@d7e9ba90ba3b08308d8379b401c1317dbd443782 | |
with: | |
ocaml-compiler: ${{ matrix.ocaml-compiler }} | |
dune-cache: true | |
opam-disable-sandboxing: true | |
- name: Install deps | |
run: opam install . --deps-only --with-doc --with-test | |
- name: Pin some deps | |
run: make pin | |
- name: Build | |
run: make build | |
- name: Check formatting | |
run: make format-check | |
- name: Run tests | |
run: make test | |
- name: Web build | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
cd website | |
npm ci | |
npm run build-production | |
- name: Deploy to prod | |
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 --prod --dir=build | |
- name: Deploy preview | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
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=build | |
- name: Upload artifacts for ${{ matrix.os }} | |
uses: actions/upload-artifact@master | |
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@master | |
with: | |
name: bundled | |
path: _build/default/js/Js.bc.js | |
publish: | |
needs: build | |
name: Publish | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Use Node.js 12.x | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 12.x | |
- name: Generate NPM package and release | |
run: node scripts/make-npm-release.js | |
- name: Download JavaScript artifact | |
if: ${{ success() }} | |
uses: actions/download-artifact@master | |
with: | |
name: bundled | |
path: _release/bundled | |
- name: Download linux artifacts | |
if: ${{ success() }} | |
uses: actions/download-artifact@master | |
with: | |
name: ubuntu-latest-artifact | |
path: _release/platform-linux-x64 | |
- name: Download macOS artifacts | |
if: ${{ success() }} | |
uses: actions/download-artifact@master | |
with: | |
name: macos-latest-artifact | |
path: _release/platform-darwin-x64 | |
- name: Download windows artifacts | |
uses: actions/download-artifact@master | |
with: | |
name: windows-latest-artifact | |
path: _release/platform-windows-x64 | |
- name: Publish query-json from linux artifcats | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
cp _release/platform-linux-x64/Bin.exe ./query-json | |
chmod +x query-json | |
- 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: ${{ success() && github.event_name != 'pull_request' }} | |
id: newVersion | |
run: | | |
REMOTE=$(npm view @davesnx/query-json version); | |
CURRENT=$(cat dune-project | grep -oE '\(version [0-9]+\.[0-9]+\.[0-9]+\)' | grep -o '\d\+.\d\+.\d\+'); | |
if [ "$REMOTE" != "$CURRENT" ] | |
then | |
echo "::set-output name=shouldPublish::true"; | |
else | |
echo "::set-output name=shouldPublish::false"; | |
fi | |
- name: Publish | |
if: ${{ success() && github.event_name != 'pull_request' && 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 "::set-output name=sha_short::$(git rev-parse --short HEAD)" | |
- name: Publish Prerelease | |
if: ${{ github.event_name == 'pull_request' }} | |
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: ${{ success() && steps.newVersion.outputs.shouldPublish == 'true' }} | |
id: create_release | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.sha.outputs.sha_short }} | |
release_name: Release ${{ steps.sha.outputs.sha_short }} | |
draft: false | |
prerelease: true | |
- name: Upload query-json-darwin-x64.zip to Github release | |
if: ${{ success() && steps.newVersion.outputs.shouldPublish == 'true' }} | |
uses: actions/[email protected] | |
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/gzip | |
- name: Upload query-json-linux-x64.zip to Github release | |
if: ${{ success() && steps.newVersion.outputs.shouldPublish == 'true' }} | |
uses: actions/[email protected] | |
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/gzip | |
- name: Upload query-json-windows-x64.zip to Github release | |
if: ${{ success() && steps.newVersion.outputs.shouldPublish == 'true' }} | |
uses: actions/[email protected] | |
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/gzip |