x-compilation: update setup #361
Workflow file for this run
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: Main workflow | |
on: [push, pull_request] | |
jobs: | |
create_draft_release: | |
runs-on: ubuntu-latest | |
outputs: | |
upload_url: ${{ steps.create_draft_release.outputs.upload_url }} | |
steps: | |
- name: Create draft release on tags | |
id: create_draft_release | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: ${{ github.ref }} | |
draft: true | |
prerelease: false | |
build: | |
needs: create_draft_release | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- macos-latest | |
- ubuntu-latest | |
- windows-latest | |
ocaml-version: | |
- 4.12.x | |
include: | |
- os: macos-latest | |
suffix: x86_64-apple-darwin | |
- if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
os: ubuntu-latest | |
suffix: x86_64-unknown-linux-gnu | |
- os: windows-latest | |
suffix: x86_64-pc-windows-gnu | |
env: | |
OCAML_VERSION: ${{ matrix.ocaml-version }} | |
OS: ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Use OCaml ${{ matrix.ocaml-version }} | |
uses: ocaml/setup-ocaml@v2 | |
with: | |
ocaml-compiler: ${{ matrix.ocaml-version }} | |
dune-cache: true | |
- name: Set git user | |
run: | | |
git config --global user.name github-actions | |
git config --global user.email [email protected] | |
- name: Define env (unix) | |
if: ${{ runner.os != 'Windows' }} | |
run: | | |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV | |
echo "OPAMJOBS=1" >> $GITHUB_ENV | |
- name: Define env (windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: | | |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV | |
echo "OPAMJOBS=1" >> $GITHUB_ENV | |
- name: Install dependencies | |
if: ${{ !startsWith(runner.os, 'Mac') }} | |
run: | | |
opam depext tls decompress | |
opam install tls decompress | |
- name: Build project | |
run: | | |
opam install --deps-only . | |
opam exec -- dune build -p doi2bib | |
- name: Check code formatting | |
if: ${{ success() && startsWith(runner.os, 'Linux') }} | |
run: | | |
opam install ocamlformat | |
opam exec -- dune build @fmt | |
- name: Run tests | |
if: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
run: opam exec -- dune runtest | |
- name: Build | |
run: opam exec -- dune build -p doi2bib | |
- name: Create release archive | |
if: ${{ startsWith(github.ref, 'refs/tags/') && !startsWith(runner.os, 'Win') }} | |
run: opam exec -- tar czf release.tar.gz -C _build/default/bin/ doi2bib.exe | |
- name: Create release archive (Windows) | |
if: ${{ startsWith(github.ref, 'refs/tags/') && startsWith(runner.os, 'Win') }} | |
run: | | |
opam exec -- dos2unix .github/scripts/win.sh | |
opam exec -- bash .github/scripts/win.sh | |
opam exec -- tar czf release.tar.gz out/ | |
- name: Upload build artifact | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
uses: actions/upload-artifact@v2 | |
with: | |
path: release.tar.gz | |
name: doi2bib-${{ env.GITHUB_TAG }}-${{ matrix.suffix }}.tar.gz | |
if-no-files-found: error | |
- name: Upload release tarball | |
if: ${{ startsWith(github.ref, 'refs/tags/') }} | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_draft_release.outputs.upload_url }} | |
asset_path: release.tar.gz | |
asset_name: doi2bib-${{ env.GITHUB_TAG }}-${{ matrix.suffix }}.tar.gz | |
asset_content_type: application/zip | |
nix-build: | |
needs: create_draft_release | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
platform: [musl, arm64-musl] | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: cachix/install-nix-action@v18 | |
with: | |
extra_nix_config: | | |
extra-substituters = https://anmonteiro.nix-cache.workers.dev | |
extra-trusted-public-keys = ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY= | |
- name: "Run nix-build" | |
run: nix build -L .#${{ matrix.platform }} | |
- name: Prepare env | |
if: ${{ success() }} | |
run: | | |
echo "GITHUB_TAG=$(git describe --always --tags)" >> $GITHUB_ENV | |
if [[ ${{ matrix.platform }} == "musl" ]]; then | |
echo "ARCH=x86_64" >> $GITHUB_ENV | |
else | |
echo "ARCH=arm64" >> $GITHUB_ENV | |
fi | |
- name: Create release archive | |
if: ${{ success() }} | |
run: tar czf release.tar.gz -C ./result/bin doi2bib | |
- name: Upload build artifact | |
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }} | |
uses: actions/upload-artifact@v2 | |
with: | |
path: release.tar.gz | |
name: doi2bib-${{ env.GITHUB_TAG }}-${{ env.ARCH }}-unknown-linux-musl.tar.gz | |
if-no-files-found: error | |
- name: Upload release tarball | |
if: ${{ success() && startsWith(github.ref, 'refs/tags/') }} | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.create_draft_release.outputs.upload_url }} | |
asset_path: release.tar.gz | |
asset_name: doi2bib-${{ env.GITHUB_TAG }}-${{ env.ARCH }}-unknown-linux-musl.tar.gz | |
asset_content_type: application/zip | |