Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/scripts/add_experimental_flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -euo pipefail

MATRIX_FILE="$1"
CABAL_FILE="$2"

if [[ -z "$MATRIX_FILE" || ! -f "$MATRIX_FILE" ]]; then
echo "Usage: $0 matrix_file path/to/package.cabal"
exit 1
fi

if [[ -z "$CABAL_FILE" || ! -f "$CABAL_FILE" ]]; then
echo "Cabal file missing: $CABAL_FILE"
exit 1
fi

MATRIX_JSON=$(sed -E 's/^matrix=//' < "$MATRIX_FILE")

readarray -t EXP_FLAGS < <(awk '
/^flag / { flag=$2; in_desc=0 }
/^ *description:/ { in_desc=1; if ($0 ~ /\(experimental\)/) print flag; next }
in_desc && /^[[:space:]]+/ { if ($0 ~ /\(experimental\)/) print flag; next }
/^[^[:space:]]/ { in_desc=0 }
' "$CABAL_FILE")

ORIGINAL=$(jq --arg label "stable" '.include[0] += {label: $label}' <<<"$MATRIX_JSON")

if [[ ${#EXP_FLAGS[@]} -eq 0 ]]; then
UPDATED="$ORIGINAL"
else
EXP_FLAGS_STRING=$(printf '+%s ' "${EXP_FLAGS[@]}")
EXPERIMENTAL=$(jq --arg flags "$EXP_FLAGS_STRING" --arg label "experimental" \
'.include[0] += {flags: $flags, label: $label}' <<<"$MATRIX_JSON")

UPDATED=$(jq --argjson exp_include "$(jq '.include' <<<"$EXPERIMENTAL")" \
'.include += $exp_include' <<<"$ORIGINAL")
fi

echo "$UPDATED" | jq -c .
66 changes: 56 additions & 10 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
get-newest-supported-ghc:
name: Get the newest supported GHC
outputs:
matrix: ${{ steps.get-latest-version.outputs.matrix }}
matrix: ${{ steps.add-exp.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- name: Extract the tested GHC versions
Expand All @@ -21,10 +21,24 @@ jobs:
windows-version: latest
version: get-tested-for-jbeam-edit
newest: true
- uses: actions/checkout@v5
- name: Add experimental flags
id: add-exp
shell: bash
run: |
echo "$OLD_MATRIX" > matrix.json
echo "checking input matrix"
cat matrix.json
MATRIX="$(bash ./.github/scripts/add_experimental_flags.sh matrix.json jbeam-edit.cabal)"
echo "checking output matrix"
echo $MATRIX
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
env:
OLD_MATRIX: ${{ steps.get-latest-version.outputs.matrix }}
build-for-release:
runs-on: windows-latest
needs: get-newest-supported-ghc
name: Build for release for ${{ matrix.ghc }}
name: Build for release for ${{ matrix.ghc }} (${{ matrix.label}})
strategy:
matrix: ${{ fromJSON(needs.get-newest-supported-ghc.outputs.matrix) }}
steps:
Expand All @@ -42,6 +56,13 @@ jobs:
- name: Enable tests for non-tags
if: "!startsWith(github.ref, 'refs/tags/')"
run: cabal configure --project-file cabal.project.release --enable-tests
- name: Configure Cabal with flags from matrix
shell: bash
run: |
printf 'package jbeam-edit\n flags: %s' $MATRIX_FLAGS >> cabal.project.release.local
cat cabal.project.release.local
env:
MATRIX_FLAGS: ${{ matrix.flags }}
- name: Cache GHC, Cabal store, and build artifacts
uses: actions/cache@v4.2.4
if: "!startsWith(github.ref, 'refs/tags/')"
Expand All @@ -65,13 +86,13 @@ jobs:
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: jbeam-edit-${{ matrix.ghc }}
name: jbeam-edit-${{ matrix.ghc }}-${{ matrix.label }}
path: dist-newstyle
release:
prepare-for-release:
runs-on: windows-latest
needs: [build-for-release, get-newest-supported-ghc]
if: startsWith(github.ref, 'refs/tags/')
name: Release for Windows
name: Prepare release for Windows
strategy:
matrix: ${{ fromJSON(needs.get-newest-supported-ghc.outputs.matrix) }}
env:
Expand All @@ -84,7 +105,7 @@ jobs:
- name: Download build artifact
uses: actions/download-artifact@v5.0.0
with:
name: jbeam-edit-${{ matrix.ghc }}
name: jbeam-edit-${{ matrix.ghc }}-${{ matrix.label }}
path: ${{ env.DIST_NEWSTYLE }}
- name: Extract files from cabal
shell: bash
Expand All @@ -104,15 +125,40 @@ jobs:
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$zipFile = "$env:GITHUB_WORKSPACE\dist\jbeam-edit-${env:GITHUB_REF_NAME}.zip"
$zipFile = "$env:GITHUB_WORKSPACE\dist\jbeam-edit-${env:GITHUB_REF_NAME}-${env:LABEL}.zip"
$zipDir = "$env:GITHUB_WORKSPACE\dist\zip_temp"
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::CreateFromDirectory($zipDir, $zipFile)
- name: Create GitHub Release and upload zip
env:
LABEL: ${{ matrix.label}}
- name: Upload zip artifact
uses: actions/upload-artifact@v4
with:
name: jbeam-edit-${{ github.ref_name }}-${{ matrix.label }}.zip
path: dist/jbeam-edit-${{ github.ref_name }}-${{ matrix.label }}.zip
release:
runs-on: windows-latest
needs: [prepare-for-release]
if: startsWith(github.ref, 'refs/tags/')
name: Release for Windows
steps:
- uses: actions/checkout@v5
- name: Download all prepared zip artifacts
uses: actions/download-artifact@v5
with:
pattern: jbeam-edit-${{ github.ref_name }}-*.zip
path: dist
- name: Collect zip files to single folder
shell: bash
run: |
set -euo pipefail
mkdir -p dist_flat
find dist -type f -name '*.zip' -print0 | xargs -0 -I{} mv {} dist_flat/
ls -la dist_flat
- name: Create GitHub Release and upload zips
uses: softprops/action-gh-release@v2.3.2
with:
tag_name: ${{ github.ref_name }}
draft: true
generate_release_notes: true
files: |-
dist/jbeam-edit-${{ github.ref_name }}.zip
files: dist_flat/*.zip
Loading