Skip to content

Turn default.nix into a function #151

Turn default.nix into a function

Turn default.nix into a function #151

name: Build and publish application binaries
on: [push]
jobs:
# ########################################################################## #
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ghc: ['8.10.7', '9.0.2', '9.2', '9.4']
cabal: ['3.8']
os: ['ubuntu-20.04', 'ubuntu-22.04', 'macOS-latest']
steps:
- name: Set Variables
id: vars
shell: bash
run: |
cat >> $GITHUB_ENV <<EOF
SHORT_SHA=${GITHUB_SHA::7}
ARTIFACTS_DIR=./artifacts/chainweb-mining-client
ARTIFACTS_NAME=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}
ARTIFACTS_ARCHIVE=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}.${GITHUB_SHA::7}.tar.gz
EOF
# Setup
- name: Checkout repository
uses: actions/checkout@v3
- name: Install GHC and Cabal
uses: haskell/actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
- name: Confirm GHC and Cabal installation
run: |
ghc --version
cabal --version
- uses: actions/cache@v3
name: Cache dist-newstyle
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ matrix.os }}-${{ matrix.ghc }}-1-cabal
# Build
- name: Update package database
run: cabal update
- name: Configure build
run: |
rm -rf dist-newstyle/build/*/ghc-*/chainweb-mining-client-*/build/chainweb-mining-client/chainweb-mining-client
cabal build all --dry-run --enable-tests
cabal freeze --enable-tests
- name: Install build dependencies
run: cabal build --only-dependencies --enable-tests
- name: Build
run: cabal build
# Tests
- name: Run Tests
run: cabal test
# Artifacts
- name: Prepare artifacts
run: |
echo "ARTIFACTS_ARCHIVE: $ARTIFACTS_ARCHIVE"
mkdir -p $ARTIFACTS_DIR
cp $(cabal list-bin chainweb-mining-client) $ARTIFACTS_DIR
cp README.md $ARTIFACTS_DIR
cp CHANGELOG.md $ARTIFACTS_DIR
cp LICENSE $ARTIFACTS_DIR
cp chainweb-mining-client.cabal $ARTIFACTS_DIR
cp cabal.project $ARTIFACTS_DIR
cp cabal.project.freeze $ARTIFACTS_DIR
tar -C ./artifacts/ -czf "$ARTIFACTS_ARCHIVE" chainweb-mining-client
- name: Safe artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACTS_NAME }}
path: ${{ env.ARTIFACTS_ARCHIVE }}
if-no-files-found: error
# ########################################################################## #
docker-image:
name: Build and publish docker image
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ghc: ["9.2"]
os: ["ubuntu-22.04"]
env:
GHC_VERSION: ${{ matrix.ghc }}
OS: ${{ matrix.os }}
COMPILER: ghc-${{ matrix.ghc }}
steps:
- name: Set Variables
id: vars
shell: bash
run: |
cat >> $GITHUB_ENV <<EOF
SHORT_SHA=${GITHUB_SHA::7}
ARTIFACTS_NAME=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}
ARTIFACTS_ARCHIVE=chainweb-mining-client-${{ matrix.ghc }}.${{ matrix.os }}.${GITHUB_SHA::7}.tar.gz
EOF
- name: Get build artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACTS_NAME }}
path: .
- name: Extract artifacts
run: |
tar -xzf "$ARTIFACTS_ARCHIVE"
- name: Create Dockerfile
run: |
cat > Dockerfile <<EOF
FROM ubuntu:${OS#ubuntu-}
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /chainweb-mining-client
COPY chainweb-mining-client/chainweb-mining-client .
COPY chainweb-mining-client/LICENSE .
COPY chainweb-mining-client/README.md .
COPY chainweb-mining-client/CHANGELOG.md .
COPY chainweb-mining-client/chainweb-mining-client.cabal .
COPY chainweb-mining-client/cabal.project .
COPY chainweb-mining-client/cabal.project.freeze .
ENTRYPOINT [ "/chainweb-mining-client/chainweb-mining-client" ]
EOF
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/kadena-io/chainweb-mining-client
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
push: true
context: .
file: ./Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}