Skip to content

Commit

Permalink
build: Add GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jan 7, 2025
1 parent 4cfb730 commit eb9eb2b
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 3 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/early-access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: EarlyAccess

on:
push:
branches: [ main ]

jobs:
precheck:
if: github.repository == 'jreleaser/helloworld-ocaml' && startsWith(github.event.head_commit.message, 'Releasing version') != true
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.vars.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cancel previous run
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Version
id: vars
shell: bash
run: |
VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
build:
needs: [ precheck ]
if: endsWith(${{ needs.precheck.outputs.VERSION }}, '-SNAPSHOT')
uses: jreleaser/helloworld-ocaml/.github/workflows/reusable-build.yml@main
with:
version: ${{ needs.precheck.outputs.VERSION }}

release:
needs: [ precheck, build ]
if: endsWith(${{ needs.precheck.outputs.VERSION }}, '-SNAPSHOT')
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: artifact-*
merge-multiple: true
path: out/jreleaser/assemble/helloworld/archive

- name: Release
uses: jreleaser/release-action@v2
with:
arguments: release
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
79 changes: 79 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true

jobs:
precheck:
name: Precheck
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.vars.outputs.VERSION }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cancel previous run
uses: styfle/cancel-workflow-action@0.12.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Version
id: vars
shell: bash
run: |
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
build:
needs: [ precheck ]
uses: jreleaser/helloworld-ocaml/.github/workflows/reusable-build.yml@main
with:
version: ${{ needs.precheck.outputs.VERSION }}

release:
name: Release
needs: [ precheck, build ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: artifact-*
merge-multiple: true
path: out/jreleaser/assemble/helloworld/archive

- name: Commit version
run: |
echo ${{ github.event.inputs.version }} > VERSION
git add VERSION
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Action"
git commit -a -m "Releasing version ${{ needs.precheck.outputs.VERSION }}"
git push origin main
- name: Release
uses: jreleaser/release-action@v2
with:
version: early-access
arguments: release
env:
JRELEASER_PROJECT_VERSION: ${{ needs.precheck.outputs.VERSION }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v4
with:
name: jreleaser-release
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
51 changes: 51 additions & 0 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build

on:
workflow_call:
inputs:
version:
required: true
type: string

jobs:
build:
name: 'Build ${{ matrix.os }}'
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, macos-13]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup OCaml
uses: ocaml/setup-ocaml@v3
with:
ocaml-compiler: 5

- name: Assemble
uses: jreleaser/release-action@v2
with:
version: early-access
arguments: assemble --select-current-platform
env:
JRELEASER_PROJECT_VERSION: ${{ inputs.version }}
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: JReleaser output
if: always()
uses: actions/upload-artifact@v4
with:
name: jreleaser-assemble-${{ runner.os }}-${{ runner.arch }}
path: |
out/jreleaser/trace.log
out/jreleaser/output.properties
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
retention-days: 1
name: artifact-${{ runner.os }}-${{ runner.arch }}
path: |
out/jreleaser/assemble/helloworld/archive/*.zip
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
target/
out/
*.cmx
*.cmd
*.o
1 change: 0 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ This repository shows how to configure link:https://github.com/features/actions[
** osx-aarch_64
** osx-x86_64
** linux-x86_64
** windows-x86_64
* assemble zip distributions with JReleaser
* create rolling early-access releases with JReleaser on every push to `main` branch

Expand Down
4 changes: 2 additions & 2 deletions jreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ matrix:
- { ext: '', platform: osx-aarch_64 }
- { ext: '', platform: osx-x86_64 }
- { ext: '', platform: linux-x86_64 }
- { ext: '.exe', platform: windows-x86_64 }
#- { ext: '.exe', platform: windows-x86_64 }

hooks:
script:
before:
- run: |
echo "Compiling {{ matrix.platform }}"
mkdir -p target/{{ matrix.platform }}
ocamlopt -o target/{{ matrix.platform }}/helloworld{{ matrix.ext }} src/helloworld.ml
opam exec -- ocamlc -o target/{{ matrix.platform }}/helloworld{{ matrix.ext }} src/helloworld.ml
verbose: true
applyDefaultMatrix: true
verbose: true
Expand Down
Binary file removed src/helloworld.cmi
Binary file not shown.
Binary file removed src/helloworld.cmx
Binary file not shown.
Binary file removed src/helloworld.o
Binary file not shown.

0 comments on commit eb9eb2b

Please sign in to comment.