Skip to content

Commit

Permalink
Use the same Workflow as in print-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleidukos committed Sep 2, 2024
1 parent a292cd3 commit cd03592
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 55 deletions.
125 changes: 73 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ name: Tests Pipeline
on:
pull_request:
push:
branches: ['main']
branches: ["main"]

jobs:
generate-matrix:
name: 'Generate matrix from cabal'
outputs:
name: "Generate matrix from cabal"
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
runs-on: ubuntu-latest
steps:
Expand All @@ -17,16 +17,21 @@ jobs:
uses: kleidukos/get-tested@0.1.7.1
with:
cabal-file: get-tested.cabal
ubuntu-version: 'latest'
macos-version: 'latest'
ubuntu-version: latest
version: 0.1.7.0
build:
name: Build with ${{ matrix.ghc }} on ${{ matrix.os }}
name: ${{ matrix.ghc }} on ${{ matrix.os }}
needs: generate-matrix
runs-on: ${{ matrix.os }}
strategy:
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
steps:

- name: "Install tools"
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt install upx-ucl
- name: Checkout base repo
uses: actions/checkout@v4

Expand All @@ -35,66 +40,74 @@ jobs:
uses: haskell-actions/setup@v2
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: 'latest'
cabal-version: "latest"

- name: Configure
run: |
ARCHITECTURE=$(uname -m)
echo "ARCH=$ARCHITECTURE" >> $GITHUB_ENV
echo "REPORT_NAME=report-${{ matrix.os }}-ghc-${{ matrix.ghc }}.xml" >> $GITHUB_ENV
echo ${{ env.ARCH }}
cabal configure --enable-tests
- name: Freeze
run: cabal freeze --project-file=cabal.release.project

- name: Cache
uses: actions/cache@v4.0.2
uses: actions/cache@v4
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ runner.os }}-ghc-${{ matrix.ghc }}-${{ hashFiles('**/plan.json') }}
path: ${{ steps.setup-haskell.outputs.cabal-store }}
restore-keys: ${{ runner.os }}-ghc-${{ matrix.ghc }}-

- name: Build
run: cabal build --project-file=cabal.release.project

- name: Run Tests
run: cabal test --project-file=cabal.release.project all
- name: Test
run: |
cabal test --project-file=cabal.release.project --test-options "--xml=../get-tested/${{ env.REPORT_NAME }}" all
- name: Upload the test report
uses: actions/upload-artifact@v4
if: success() || failure() # always run even if the previous step fails
with:
name: test-report
path: test-report.xml
name: ${{ env.REPORT_NAME }}
path: ${{ env.REPORT_NAME }}

- name: Install
run: |
bin=$(cabal -v0 --project-file=cabal.release.project list-bin get-tested)
mkdir distribution
cp ${bin} distribution/get-tested
- name: File type
run: file distribution/get-tested
- name: Post-process executables
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
for executable in distribution/*; do
strip "${executable}"
upx -9 "${executable}"
done
- name: Package the get-tested executable
run: |
GETTESTED_EXEC=distribution/get-tested
.github/workflows/process-binaries.sh
archive="get-tested-head-${{ matrix.os }}-${{ env.ARCH }}-ghc-${{ matrix.ghc }}.tar.gz"
DIR=$(dirname $GETTESTED_EXEC)
FILE=$(basename $GETTESTED_EXEC)
GETTESTED_EXEC_TAR=get-tested-head-${{ runner.os }}-${{ env.ARCH }}.tar.gz
GETTESTED_EXEC_TAR=${archive}
tar -czvf $GETTESTED_EXEC_TAR -C $DIR $FILE
echo GETTESTED_EXEC_TAR=$GETTESTED_EXEC_TAR >> $GITHUB_ENV
echo "ARTIFACT_NAME= >> $GITHUB_ENV
- name: Upload the get-tested executable
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: artifact
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.GETTESTED_EXEC_TAR }}

build-alpine:
name: 9.10.1 on alpine-3.20
runs-on: ubuntu-latest
container: 'alpine:3.20'
container: "alpine:3.20"
needs: generate-matrix
steps:
- name: Install extra dependencies
Expand All @@ -111,13 +124,14 @@ jobs:
- uses: haskell-actions/setup@v2
id: setup-haskell
with:
ghc-version: '9.10.1'
cabal-version: 'latest'
ghc-version: "9.10.1"
cabal-version: "latest"

- name: Configure
run: |
ARCHITECTURE=$(uname -m)
echo "ARCH=$ARCHITECTURE" >> $GITHUB_ENV
echo "REPORT_NAME=report-alpine-ghc-9.10.1.xml" >> $GITHUB_ENV
echo ${{ env.ARCH }}
cabal configure --enable-tests
Expand All @@ -134,14 +148,15 @@ jobs:
run: cabal build --project-file=cabal.static.project

- name: Test
run: cabal test --project-file=cabal.static.project all
run: |
cabal test --project-file=cabal.static.project --test-options "--xml=../get-tested/${{ env.REPORT_NAME }}" all
- name: Upload the test report
uses: actions/upload-artifact@v4
if: success() || failure() # always run even if the previous step fails
with:
name: test-report
path: test-report.xml
name: ${{ env.REPORT_NAME }}
path: ${{ env.REPORT_NAME }}

- name: Install
run: |
Expand All @@ -152,45 +167,35 @@ jobs:
- name: File type
run: file distribution/get-tested

- name: Post-process executables
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
for executable in distribution/*; do
strip "${executable}"
upx -9 "${executable}"
done
- name: Tar get-tested executable
run: |
GETTESTED_EXEC=distribution/get-tested
.github/workflows/process-binaries.sh
DIR=$(dirname $GETTESTED_EXEC)
FILE=$(basename $GETTESTED_EXEC)
GETTESTED_EXEC_TAR=get-tested-head-${{ runner.os }}-static-${{ env.ARCH }}.tar.gz
tar -czvf $GETTESTED_EXEC_TAR -C $DIR $FILE
echo GETTESTED_EXEC_TAR=$GETTESTED_EXEC_TAR >> $GITHUB_ENV
echo "ARTIFACT_NAME=artifact-alpine-3.20-ghc-${{ matrix.ghc }}" >> $GITHUB_ENV
- name: Upload get-tested executable to workflow artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: artifact
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.GETTESTED_EXEC_TAR }}

prerelease-head:
name: Create a GitHub prerelease with the binary artifacts
runs-on: ubuntu-latest
needs: ['tests', 'build-alpine']

steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: ./out

- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: ./out/*
run: cabal test --project-file=cabal.static.project --test-options "--xml=test-report.xml" all

collect-test-results:
name: Collect test results
runs-on: ubuntu-latest
needs: ['tests']
if: ${{ always() }}
needs: ['build', 'build-alpine']
steps:
- name: Install junitparser
run: |
Expand All @@ -201,9 +206,6 @@ jobs:
with:
pattern: report-*
merge-multiple: true
workflow: ${{ github.event.workflow.id }}
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GH_PAT }} # token with actions:read permissions on target repo

- name: Merge XML files
run: |
Expand All @@ -214,3 +216,22 @@ jobs:
with:
commit: ${{github.event.workflow_run.head_sha}}
report_paths: 'final-report.xml'

prerelease-head:
name: Create a GitHub prerelease with the binary artifacts
runs-on: ubuntu-latest
needs: ["build", "build-alpine"]

steps:
- uses: actions/download-artifact@v4
with:
pattern: artifact-*
merge-multiple: true
path: ./out

- name: Pre-release
uses: softprops/action-gh-release@v2
with:
prerelease: true
files: ./out/*
tag_name: get-tested-head
1 change: 0 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ jobs:
with:
path: '["app", "test", "src"]'
fail-on: warning

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test: ## Run the test suite
lint: ## Run the code linter (HLint)
@find app src test -name "*.hs" | xargs -P $(PROCS) -I {} hlint --refactor-options="-i" --refactor {}

style: ## Run the code styler (stylish-haskell)
style: ## Run the code styler (fourmolu)
@fourmolu -q --mode inplace app src test
@cabal-fmt -i *.cabal

Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Main where

import Data.Aeson qualified as Aeson
import Data.ByteString.Char8 qualified as BS8
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.Char8 qualified as ByteString
import Data.ByteString.Char8 qualified as BS8
import Data.Function ((&))
import Data.Text (Text)
import Data.Text.Display (display)
Expand Down

0 comments on commit cd03592

Please sign in to comment.