Skip to content

Commit

Permalink
Generate github release executables for macos (#2046)
Browse files Browse the repository at this point in the history
Changes include:
- Generating executables for macos (x64 and arm)
- Simplifications to GHC and cabal setup
- Bump GH release action
- Use `softprops/action-gh-release@v1` for uploading release assets instead of archived `actions/upload-release-asset@v1.0.1`

Example release set: https://github.com/nitinprakash96/swarm-copy/releases/tag/0.8.2.8
And workflow: https://github.com/nitinprakash96/swarm-copy/actions/runs/10808335665
  • Loading branch information
nitinprakash96 committed Sep 16, 2024
1 parent 1edf55d commit ab13170
Showing 1 changed file with 115 additions and 151 deletions.
266 changes: 115 additions & 151 deletions .github/workflows/haskell-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,178 +10,142 @@ on:
- "[0-9]+.[0-9]+.[0-9]+.[0-9]+*"

jobs:
create_release:
name: Create Github Release
runs-on: ubuntu-latest
build-binaries:
name: Haskell-Release - ${{ matrix.os }} - ${{ matrix.ghc }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# macos-13 points to x64 based OS and macos-latest points to arm based OS
os:
- ubuntu-latest
- macos-latest
- macos-13
cabal:
- 3.12.1.0
ghc:
- 9.8.2

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Zip data directory
run: |
zip -r swarm-data.zip ./data || { echo "Unable to create a zip archive."; exit 1; }
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: |
LICENSE
swarm-data.zip
- name: Output Release URL File
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt

- name: Save Release URL File for publish
uses: actions/upload-artifact@v4
with:
name: release_url
path: release_url.txt

build_artifact:
needs: [create_release]
name: Haskell-Release - ${{ matrix.os }} - ${{ matrix.compiler }}
runs-on: ubuntu-20.04
container:
# It might be good idea to use older runner for building binary:
# on latest runners like fedora, it would link symbols in newer
# system libraries, so users could not run it on older OSes
image: buildpack-deps:jammy
strategy:
matrix:
include:
- compiler: ghc-9.8.2
compilerKind: ghc
compilerVersion: 9.8.2
setup-method: ghcup
steps:
- name: apt
run: |
apt-get update
apt-get install -y --no-install-recommends gnupg ca-certificates dirmngr curl git software-properties-common libtinfo5
mkdir -p "$HOME/.ghcup/bin"
curl -sL https://downloads.haskell.org/ghcup/0.1.30.0/x86_64-linux-ghcup-0.1.30.0 > "$HOME/.ghcup/bin/ghcup"
chmod a+x "$HOME/.ghcup/bin/ghcup"
"$HOME/.ghcup/bin/ghcup" install ghc "$HCVER" || (cat "$HOME"/.ghcup/logs/*.* && false)
"$HOME/.ghcup/bin/ghcup" install cabal 3.12.1.0 || (cat "$HOME"/.ghcup/logs/*.* && false)
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: Set PATH and environment variables
run: |
echo "$HOME/.cabal/bin" >> $GITHUB_PATH
echo "LANG=C.UTF-8" >> "$GITHUB_ENV"
echo "CABAL_DIR=$HOME/.cabal" >> "$GITHUB_ENV"
echo "CABAL_CONFIG=$HOME/.cabal/config" >> "$GITHUB_ENV"
HCDIR=/opt/$HCKIND/$HCVER
HC=$HOME/.ghcup/bin/$HCKIND-$HCVER
echo "HC=$HC" >> "$GITHUB_ENV"
echo "HCPKG=$HOME/.ghcup/bin/$HCKIND-pkg-$HCVER" >> "$GITHUB_ENV"
echo "HADDOCK=$HOME/.ghcup/bin/haddock-$HCVER" >> "$GITHUB_ENV"
echo "CABAL=$HOME/.ghcup/bin/cabal-3.12.1.0 -vnormal+nowrap" >> "$GITHUB_ENV"
HCNUMVER=$(${HC} --numeric-version|perl -ne '/^(\d+)\.(\d+)\.(\d+)(\.(\d+))?$/; print(10000 * $1 + 100 * $2 + ($3 == 0 ? $5 != 1 : $3))')
echo "HCNUMVER=$HCNUMVER" >> "$GITHUB_ENV"
echo "HEADHACKAGE=false" >> "$GITHUB_ENV"
echo "ARG_COMPILER=--$HCKIND --with-compiler=$HC" >> "$GITHUB_ENV"
env:
HCKIND: ${{ matrix.compilerKind }}
HCNAME: ${{ matrix.compiler }}
HCVER: ${{ matrix.compilerVersion }}
- name: env
run: |
env
- name: write cabal config
run: |
mkdir -p $CABAL_DIR
cat >> $CABAL_CONFIG <<EOF
remote-build-reporting: anonymous
write-ghc-environment-files: never
remote-repo-cache: $CABAL_DIR/packages
logs-dir: $CABAL_DIR/logs
world-file: $CABAL_DIR/world
extra-prog-path: $CABAL_DIR/bin
symlink-bindir: $CABAL_DIR/bin
installdir: $CABAL_DIR/bin
build-summary: $CABAL_DIR/logs/build.log
store-dir: $CABAL_DIR/store
install-dirs user
prefix: $CABAL_DIR
repository hackage.haskell.org
url: http://hackage.haskell.org/
EOF
cat >> $CABAL_CONFIG <<EOF
program-default-options
ghc-options: $GHCJOBS +RTS -M3G -RTS
EOF
cat $CABAL_CONFIG
- name: versions
run: |
$HC --version || true
$HC --print-project-git-commit-id || true
$CABAL --version || true
- name: update cabal index
run: |
$CABAL v2-update -v
- name: cache (tools)
uses: actions/cache@v4
- uses: haskell-actions/setup@v2
id: setup-haskell-cabal
name: Setup Haskell
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-tools-436fbe9d
path: ~/.haskell-ci-tools
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}

- name: Check out code
uses: actions/checkout@v4
- name: Freeze
run: cabal freeze

- name: cache
uses: actions/cache@v4
with:
key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }}
path: ~/.cabal/store
restore-keys: ${{ runner.os }}-${{ matrix.compiler }}-
- name: install dependencies
key: ${{ matrix.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }}
restore-keys: |
${{ matrix.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }}
${{ matrix.os }}-${{ matrix.ghc }}-
- name: Install dependencies
run: |
$CABAL v2-build $ARG_COMPILER --disable-tests --disable-benchmarks --dependencies-only -j2 all
cabal v2-build --disable-tests --disable-benchmarks --dependencies-only -j2 all
- name: Build binary
run: |
mkdir dist
$CABAL v2-install $ARG_COMPILER exe:swarm --install-method=copy --overwrite-policy=always --installdir=dist
cabal v2-install exe:swarm --install-method=copy --overwrite-policy=always --installdir=dist
- name: Set binary path name
run: echo BINARY_PATH="./dist/swarm" >> "$GITHUB_ENV"

- name: Load Release URL File from release job
uses: actions/download-artifact@v4
with:
name: release_url
- if: matrix.os == 'ubuntu-latest'
name: Set binary OS name on Ubuntu
run: echo BINARY_OS=${{ runner.os }} >> "$GITHUB_ENV"

- name: Get Release File Name & Upload URL
id: get_release_info
run: |
echo "upload_url=$(cat release_url.txt)" >> "$GITHUB_OUTPUT"
- if: (matrix.os == 'macos-13') || (matrix.os == 'macos-latest')
name: Set binary OS name on Macos
run: echo BINARY_OS="Darwin" >> "$GITHUB_ENV"

- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ${{ env.BINARY_PATH }}
asset_name: swarm-${{ runner.os }}
asset_content_type: application/octet-stream

- name: Generate tarball for Hackage
run: $CABAL v2-sdist
- name: Set binary Arch name
run: echo ARCH="x86_64" >> "$GITHUB_ENV"

# - name: Generate documentation for Hackage
# # The hackage-server attempts to build documentation for library packages, but this can fail.
# # If it does we can do it ourselves
# run: cabal v2-haddock --builddir=docs --haddock-for-hackage --enable-doc
- if: matrix.os == 'macos-latest'
name: Set binary ARCH name for apple silicon
run: echo ARCH="arm64" >> "$GITHUB_ENV"

- uses: haskell-actions/hackage-publish@v1
- name: Upload executables
uses: actions/upload-artifact@v4
with:
hackageToken: "${{ secrets.HACKAGE_AUTH_TOKEN }}"
packagesPath: dist-newstyle/sdist
# docsPath: docs
publish: true
name: swarm-${{ env.BINARY_OS }}-${{env.ARCH}}
path: ${{ env.BINARY_PATH }}
retention-days: 3

create-release:
name: Create release
needs: [build-binaries]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Download Linux x86_64
uses: actions/download-artifact@v4
with:
name: swarm-Linux-x86_64
path: artifacts/swarm-Linux-x86_64

- name: Download executable for Macos x86_64
uses: actions/download-artifact@v4
with:
name: swarm-Darwin-x86_64
path: artifacts/swarm-Darwin-x86_64

- name: Download executable for arm64 Macos
uses: actions/download-artifact@v4
with:
name: swarm-Darwin-arm64
path: artifacts/swarm-Darwin-arm64

- name: Download Swarm data
uses: actions/download-artifact@v4
with:
name: swarm-data.zip
path: artifacts/swarm-Darwin-arm64

- name: Rename executables
run: |
mv artifacts/swarm-Linux-x86_64/swarm swarm-Linux-x86_64
mv artifacts/swarm-Darwin-x86_64/swarm swarm-Darwin-x86_64
mv artifacts/swarm-Darwin-arm64/swarm swarm-Darwin-arm64
- name: Zip data directory
run: zip -r swarm-data.zip ./data || { echo "Unable to create a zip archive."; exit 1; }

- name: Upload Release Asset
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: swarm
draft: false
prerelease: false
files: |
swarm-Linux-x86_64
swarm-Darwin-x86_64
swarm-Darwin-arm64
LICENSE
swarm-data.zip
# - name: Generate documentation for Hackage
# # The hackage-server attempts to build documentation for library packages, but this can fail.
# # If it does we can do it ourselves
# run: cabal v2-haddock --builddir=docs --haddock-for-hackage --enable-doc

- uses: haskell-actions/hackage-publish@v1
with:
hackageToken: "${{ secrets.HACKAGE_AUTH_TOKEN }}"
packagesPath: dist-newstyle/sdist
# docsPath: docs
publish: true

0 comments on commit ab13170

Please sign in to comment.