diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 55b87c3..b089b31 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,41 +3,99 @@ name: Release on: release: types: [published] - + workflow_dispatch: inputs: tag: - description: 'Tag to build (optional)' + description: "Tag to build (optional)" required: false - default: '' + default: "" -permissions: read-all +permissions: + contents: write jobs: build: name: Build ${{ matrix.platform }} strategy: matrix: - os: - - ubuntu-latest - - macos-latest - - windows-latest + include: + - os: ubuntu-latest + platform: linux-x86_64 + binary_ext: "" + - os: macos-latest + platform: darwin-arm64 + binary_ext: "" + - os: windows-latest + platform: windows-x86_64 + binary_ext: ".exe" fail-fast: false - - runs-on: ${{ matrix.platform }} - + + runs-on: ${{ matrix.os }} + steps: - name: Checkout tree uses: actions/checkout@v4 + - name: Extract version from tag + id: version + shell: bash + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + if [[ -n "${{ github.event.inputs.tag }}" ]]; then + echo "VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "VERSION=dev-${{ github.sha }}" >> $GITHUB_OUTPUT + fi + else + echo "VERSION=dev-${{ github.sha }}" >> $GITHUB_OUTPUT + fi + - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: 5 - - run: opam install . --deps-only --with-test + - name: Install dependencies + run: opam install . --deps-only --with-test + + - name: Build + run: opam exec -- dune build - - run: opam exec -- dune build + - name: Run tests + run: opam exec -- dune runtest - - run: opam exec -- dune runtest - + - name: Install + run: opam install . --destdir _install + + - name: Prepare binary + shell: bash + run: | + if [ "${{ matrix.os }}" == "windows-latest" ]; then + cp _install/bin/agent-sync.exe agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} + else + cp _install/bin/agent-sync agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} + chmod +x agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} + fi + sha256sum agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} > agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }}.sha256 + + - name: Upload Release Asset + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + ./agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} + ./agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }}.sha256 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload Artifacts (Manual Build) + uses: actions/upload-artifact@v4 + if: github.event_name == 'workflow_dispatch' && !startsWith(github.ref, 'refs/tags/') + with: + name: agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }} + path: | + ./agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }} + ./agent-sync-${{ steps.version.outputs.VERSION }}-${{ matrix.platform }}${{ matrix.binary_ext }}.sha256 diff --git a/.gitignore b/.gitignore index 006f7ba..e6a9fed 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ # ocamlbuild and Dune default working directory _build/ +_install/ # ocamlbuild targets *.byte