Skip to content

use 80 length lines #1955

use 80 length lines

use 80 length lines #1955

Workflow file for this run

name: Build and publish application binaries
on:
workflow_dispatch:
push:
pull_request_target:
types: [ opened ]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
ghc: ['9.6']
cabal: ['3.10']
os: ['ubuntu-20.04', 'ubuntu-22.04', 'macOS-latest']
cabalcache: ['true']
flags: ['+build-tool']
include:
- os: 'ubuntu-22.04'
ghc: '9.6'
cabal: '3.10'
cabalcache: 'true'
flags: '-build-tool'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.kadena_cabal_cache_aws_access_key_id }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.kadena_cabal_cache_aws_secret_access_key }}
AWS_DEFAULT_REGION: us-east-1
# Aritfacts
ARTIFACT_BUCKET: kadena-cabal-cache
BINFILE: pact.${{ matrix.ghc }}.${{ matrix.os }}.${{ github.sha }}.tar.gz
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Non Haskell dependencies
# Install Z3
- name: Install z3 (ubuntu-20.04)
if: contains(matrix.os, 'ubuntu-20.04')
uses: larskuhtz/setup-z3@c209497f76e03a4c71ec92c0c6621fb3e1ea5fba
with:
version: "4.11.2"
architecture: "x64"
distribution: "glibc-2.31"
- name: Install z3 (ubuntu-22.04)
if: contains(matrix.os, 'ubuntu-22.04')
uses: larskuhtz/setup-z3@c209497f76e03a4c71ec92c0c6621fb3e1ea5fba
with:
version: "4.12.1"
architecture: "x64"
distribution: "glibc-2.35"
- name: Install z3 (macOS)
if: contains(matrix.os, 'mac')
# uses: pavpanchekha/[email protected]
uses: larskuhtz/setup-z3@c209497f76e03a4c71ec92c0c6621fb3e1ea5fba
with:
version: "4.12.1"
architecture: "x64"
distribution: "osx-10.16"
- name: Print Z3 version
shell: bash
run: z3 -version
# Haskell Setup
- name: Set permissions for .ghcup (ubuntu)
if: startsWith(matrix.os, 'ubuntu-')
run: sudo chown -R $USER /usr/local/.ghcup
- 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
# Project Setup
- name: Create cabal.project.local
shell: bash
run: |
cat > cabal.project.local <<EOF
documentation: False
package pact
tests: True
benchmarks: True
documentation: False
optimization: 1
flags: ${{ matrix.flags }} +cryptonite-ed25519
EOF
- name: Extend cabal.project.local for GHC-9.0.2
if: "startsWith(matrix.ghc, '9')"
shell: bash
run: |
cat >> cabal.project.local <<EOF
package pact
ghc-options: -Wwarn -Wunused-packages
EOF
- name: Add check for unused packages
shell: bash
run: |
cat >> cabal.project.local <<EOF
package pact
ghc-options: -Wunused-packages
EOF
- name: Print cabal.project.local
shell: bash
run: cat cabal.project.local
- uses: actions/cache@v3
name: Cache dist-newstyle
with:
path: |
~/.cabal/packages
~/.cabal/store
dist-newstyle
key: ${{ matrix.os }}-${{ matrix.ghc }}-4-cabal
# Build
- name: Update package database
shell: bash
run: cabal update
- name: Display outdated packages
run: cabal outdated
- name: Configure build
run: |
cabal build --dry-run
cabal freeze
- name: Sync from cabal cache
if: matrix.cabalcache == 'true'
uses: larskuhtz/cabal-cache-action@018b7ae0c480ba3dc4fa0cfa3a0bc1f05b7724b3
with:
bucket: "kadena-cabal-cache"
region: "us-east-1"
folder: "${{ matrix.os }}"
aws_access_key_id: "${{ secrets.kadena_cabal_cache_aws_access_key_id }}"
aws_secret_access_key: "${{ secrets.kadena_cabal_cache_aws_secret_access_key }}"
- name: Build dependencies
shell: bash
run: cabal build --only-dependencies
- name: Build
shell: bash
run: cabal build
- name: Test
shell: bash
run: cabal run tests
- name: Benchmark
shell: bash
if: "!contains(matrix.flags, '-build-tool')"
run: cabal bench
# Publish Artifacts
- name: Prepare artifacts
if: "!contains(matrix.flags, '-build-tool')"
shell: bash
run: |
export VER=$(grep '^version' pact.cabal | sed -e 's/.*: *//')
mkdir -p artifacts/pact
cp $(cabal list-bin pact) artifacts/pact
cp CHANGELOG.md artifacts/pact
cp README.md artifacts/pact
cp LICENSE artifacts/pact
cp pact.cabal artifacts/pact
cp cabal.project artifacts/pact
cp cabal.project.local artifacts/pact
cp cabal.project.freeze artifacts/pact
- name: Publish applications
if: "!contains(matrix.flags, '-build-tool')"
uses: actions/upload-artifact@v3
with:
name: pact-applications.${{ matrix.ghc }}.${{ matrix.os }}
path: artifacts/pact
# Publish to S3
- name: Publish applications to S3
if: "!contains(matrix.flags, '-build-tool')"
shell: bash
run: |
tar -C ./artifacts/pact/ -czf $BINFILE '.'
echo "created tar file: $BINFILE"
ls $BINFILE
aws s3 cp $BINFILE s3://$ARTIFACT_BUCKET/pact/
echo "uploaded tar file to S3"
aws s3api put-object-acl --bucket $ARTIFACT_BUCKET --key=pact/$BINFILE --acl public-read
echo "set public read permission"
# ########################################################################## #
# Build and publish docker image
docker-image:
name: Build and publish docker image
needs: [build]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- ghc: "9.6"
os: "ubuntu-20.04"
env:
OS: ${{ matrix.os }}
steps:
- name: Get build artifacts
uses: actions/download-artifact@v3
with:
name: pact-applications.${{ matrix.ghc }}.${{ matrix.os }}
path: pact
- name: Create Dockerfile
run: |
chmod 755 pact/pact
cat > Dockerfile <<EOF
FROM ubuntu:${OS#ubuntu-}
LABEL com.chainweb.docker.image.compiler="ghc-${{ matrix.ghc }}"
LABEL com.chainweb.docker.image.os="${{ matrix.os }}"
RUN apt-get update && apt-get install -y ca-certificates libgmp10 libssl1.1 zlib1g locales && rm -rf /var/lib/apt/lists/* && locale-gen en_US.UTF-8 && update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
ENV LANG=en_US.UTF-8
WORKDIR /pact
COPY pact/pact .
COPY pact/LICENSE .
COPY pact/README.md .
COPY pact/CHANGELOG.md .
COPY pact/pact.cabal .
COPY pact/cabal.project .
COPY pact/cabal.project.local .
COPY pact/cabal.project.freeze .
STOPSIGNAL SIGTERM
ENTRYPOINT [ "/pact/pact" ]
EOF
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/kadena-io/pact
tags: |
type=sha
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: kadena-build
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 }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache