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
34 changes: 34 additions & 0 deletions .github/scripts/configure_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -euo pipefail

IS_TAG=0
IS_EXPERIMENTAL=0

if [[ "$GITHUB_REF" == "" ]]; then
echo "GITHUB_REF must be set"
elif [[ "$GITHUB_REF" =~ ^refs/tags/ ]]; then
IS_TAG=1
cabal configure --project-file cabal.project.release -O2
else
cabal configure --project-file cabal.project.release
fi

if [[ "$LABEL" == "" ]]; then
echo "LABEL must be set"
elif [[ "$LABEL" == "experimental" ]]; then
IS_EXPERIMENTAL=1
fi

if [[ $IS_EXPERIMENTAL -eq 1 ]] || [[ $IS_TAG -eq 0 ]]; then
echo "package jbeam-edit" >>cabal.project.release.local
if [[ $IS_EXPERIMENTAL -eq 1 ]]; then
echo " flags: $MATRIX_FLAGS" >>cabal.project.release.local
fi
if [[ $IS_TAG -eq 0 ]]; then
echo " tests: True" >>cabal.project.release.local
fi
fi

echo "contents of cabal.project.release.local"
cat cabal.project.release.local
38 changes: 0 additions & 38 deletions .github/scripts/copy_example_files.sh

This file was deleted.

17 changes: 0 additions & 17 deletions .github/scripts/copy_exe_to_release.sh

This file was deleted.

9 changes: 9 additions & 0 deletions .github/scripts/freeze_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail

cabal freeze --project-file "${CABAL_PROJECT:?CABAL_PROJECT missing}"
PLAN_PATH=$(find dist-newstyle -name plan.json)
JQ_QUERY='."install-plan" | map (."pkg-name") | unique'
jq -c "$JQ_QUERY" < "$PLAN_PATH"
printf "number of dependencies: %d" "$(jq -r "${JQ_QUERY}.[]" < "$PLAN_PATH" | wc -l)"
72 changes: 72 additions & 0 deletions .github/scripts/prepare_installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

set -euo pipefail

DIST_NEWSTYLE="${DIST_NEWSTYLE:?Environment variable DIST_NEWSTYLE is required}"
CABAL_FILE="${CABAL_FILE:?Environment variable CABAL_FILE is required}"
DEST_DIR_RELEASE="${RELEASE_DIR:?Environment variable RELEASE_DIR is required}"
DEST_DIR_ZIP="${ZIP_DIR:?Environment variable ZIP_DIR is required}"

[[ -f "$CABAL_FILE" ]] || {
echo "Error: cabal file '$CABAL_FILE' does not exist"
exit 1
}
mkdir -p "$DEST_DIR_RELEASE"
mkdir -p "$DEST_DIR_ZIP"

get_cabal_field() {
local cabal_file="$1"
local field="$2"
awk -v field="$field" '
BEGIN { in_field=0 }
$0 ~ "^"field":" { in_field=1; next }
in_field && /^[^[:space:]]/ { in_field=0 }
in_field { gsub(/^[[:space:]]+/, ""); print }
' "$cabal_file"
}

while IFS= read -r file; do
[[ -z "$file" ]] && continue
mkdir -p "$(dirname "$DEST_DIR_RELEASE/$file")"
cp -r "$file" "$DEST_DIR_RELEASE/$file"
mkdir -p "$(dirname "$DEST_DIR_ZIP/$file")"
cp -r "$file" "$DEST_DIR_ZIP/$file"
done < <(get_cabal_field "$CABAL_FILE" "data-files")

while IFS= read -r file; do
[[ -z "$file" ]] && continue
mkdir -p "$(dirname "$DEST_DIR_ZIP/$file")"
cp -r "$file" "$DEST_DIR_ZIP/$file"
done < <(get_cabal_field "$CABAL_FILE" "extra-source-files")

EXE_PATH=$(find "$DIST_NEWSTYLE/build" -type f -name "jbeam-edit.exe" | head -n 1)

if [ -z "$EXE_PATH" ]; then
echo "Error: No exe found in '$DIST_NEWSTYLE/build'. Make sure the build step succeeded."
exit 1
fi

cp "$EXE_PATH" "$DEST_DIR_RELEASE/jbeam-edit.exe"
echo "Copied exe to /$DEST_DIR_RELEASE/jbeam-edit.exe"

TMP_DIR=$(mktemp -d)
git show HEAD:"./examples/jbeam/fender.jbeam" >"$TMP_DIR/fender.${LABEL}.jbeam"
git show HEAD:"./examples/jbeam/suspension.jbeam" >"$TMP_DIR/suspension.${LABEL}.jbeam"

echo "fender.jbeam: $TMP_DIR/fender.${LABEL}.jbeam"
echo "suspension.jbeam: $TMP_DIR/suspension.${LABEL}.jbeam"

./dist/release/jbeam-edit -i "$TMP_DIR/fender.${LABEL}.jbeam"
./dist/release/jbeam-edit -i "$TMP_DIR/suspension.${LABEL}.jbeam"

custom_diff() {
diff --color=always --suppress-common-lines "$1" "$2"
}

if [[ -n $LABEL ]] && [[ "$LABEL" == "experimental" ]]; then
custom_diff "$TMP_DIR/fender.experimental.jbeam" ./examples/transformed_jbeam/fender-cfg-default.jbeam
custom_diff "$TMP_DIR/suspension.experimental.jbeam" ./examples/transformed_jbeam/suspension-cfg-default.jbeam
else
custom_diff "$TMP_DIR/fender.stable.jbeam" ./examples/formatted_jbeam/fender-minimal-jbfl.jbeam
custom_diff "$TMP_DIR/suspension.stable.jbeam" ./examples/formatted_jbeam/suspension-minimal-jbfl.jbeam
fi
9 changes: 1 addition & 8 deletions .github/scripts/prepare_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,4 @@ fi

cp "$SETUP_EXE" "$ZIP_DIR/"

for f in README.md JBFL_DOCS.md LICENSE; do
SRC="$RELEASE_DIR/$f"
if [ -f "$SRC" ]; then
cp "$SRC" "$ZIP_DIR/"
else
echo "Warning: $f not found in release folder, skipping."
fi
done
7z a -tzip "dist/jbeam-edit-${GITHUB_REF_NAME}-${LABEL}.zip" ./dist/zip_temp/*
26 changes: 0 additions & 26 deletions .github/scripts/test_release.sh

This file was deleted.

57 changes: 19 additions & 38 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,17 @@ jobs:
ghc-version: ${{ matrix.ghc }}
cabal-version: latest
cabal-update: true
- name: Enable optimization for building on tags
if: startsWith(github.ref, 'refs/tags/')
run: cabal configure --project-file cabal.project.release -O2
- 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
if: matrix.label == 'experimental'
shell: bash
run: |
printf 'package jbeam-edit\n flags: %s' $MATRIX_FLAGS >> cabal.project.release.local
echo "contents of cabal.project.release.local"
cat cabal.project.release.local
- name: Configure
run: bash ./.github/scripts/configure_project.sh
env:
GITHUB_REF: ${{ github.ref }}
LABEL: ${{ matrix.label }}
MATRIX_FLAGS: ${{ matrix.flags }}
- name: Freeze and check dependencies
env:
CABAL_PROJECT: cabal.project.release
shell: bash
run: bash ./.github/scripts/freeze_dependencies.sh
- name: Cache GHC, Cabal store, and build artifacts
uses: actions/cache@v4.3.0
if: "!startsWith(github.ref, 'refs/tags/')"
Expand All @@ -78,7 +74,7 @@ jobs:
}}-${{
matrix.label
}}-${{
hashFiles('**/package.yaml')
hashFiles('**/dist-newstyle/**/plan.json')
}}
restore-keys: |
${{ runner.os }}-cabal-${{ matrix.ghc }}-${{ matrix.label }}
Expand All @@ -95,59 +91,44 @@ jobs:
shell: bash
- name: Test executable
shell: bash
run: bash ./.github/scripts/test_release.sh
run: bash ./.github/scripts/prepare_installer.sh
env:
RELEASE_DIR: dist/release
ZIP_DIR: dist/zip_temp
DIST_NEWSTYLE: dist-newstyle
CABAL_FILE: jbeam-edit.cabal
LABEL: ${{ matrix.label}}
- name: Upload build artifact
uses: actions/upload-artifact@v4
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-artifact@v4.6.2
with:
name: jbeam-edit-${{ matrix.ghc }}-${{ matrix.label }}
path: dist-newstyle
path: dist
prepare-for-release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: windows-latest
needs: [build-for-release, get-newest-supported-ghc]
if: startsWith(github.ref, 'refs/tags/')
name: Prepare release for Windows
strategy:
matrix: ${{ fromJSON(needs.get-newest-supported-ghc.outputs.matrix) }}
env:
RELEASE_DIR: dist/release
ZIP_DIR: dist/zip_temp
DIST_NEWSTYLE: dist-newstyle
CABAL_FILE: jbeam-edit.cabal
RELEASE_DIR: ./dist/release
ZIP_DIR: ./dist/zip_temp
steps:
- uses: actions/checkout@v5
- name: Download build artifact
uses: actions/download-artifact@v5.0.0
with:
name: jbeam-edit-${{ matrix.ghc }}-${{ matrix.label }}
path: ${{ env.DIST_NEWSTYLE }}
- name: Extract files from cabal
shell: bash
run: bash .github/scripts/copy_example_files.sh
- name: Copy exe to release folder
shell: bash
run: bash .github/scripts/copy_exe_to_release.sh
path: dist
- name: Build Inno Setup Installer
uses: Minionguyjpro/Inno-Setup-Action@v1.2.7
with:
path: installer/setup.iss
options: /O+
- name: Prepare release
shell: bash
run: bash .github/scripts/prepare_release.sh
- name: Package the release
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$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)
run: bash ./.github/scripts/prepare_release.sh
env:
LABEL: ${{ matrix.label}}
- name: Upload zip artifact
Expand Down
20 changes: 14 additions & 6 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions:

jobs:
build-with-stack:
if: github.event.pull_request.draft != true
name: Build and test on ${{ matrix.os }}
runs-on: ${{ matrix.runner }}
strategy:
Expand Down Expand Up @@ -125,6 +126,7 @@ jobs:
ubuntu-version: latest
version: 0.1.7.1
build-with-cabal:
if: github.event.pull_request.draft != true
name: Build and test with Cabal (GHC ${{ matrix.ghc }})
needs: generate-matrix
runs-on: ubuntu-latest
Expand All @@ -139,25 +141,31 @@ jobs:
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: latest
cabal-update: false
- name: Log GHC and Cabal outputs
run: |
run: |-
echo "GHC Version: ${{ steps.setup-ghc.outputs.ghc-version }}"
echo "Cabal Store Path: ${{ steps.setup-ghc.outputs.cabal-store }}"
- name: Freeze and check dependencies
env:
CABAL_PROJECT: cabal.project.ci
shell: bash
run: bash ./.github/scripts/freeze_dependencies.sh
- name: Cache Cabal store and build artifacts
uses: actions/cache@v4.3.0
with:
path: |
${{ steps.setup-ghc.outputs.cabal-store }}
~/.cabal/packages
dist-newstyle
key: >-
${{ runner.os }}-cabal-${{ matrix.ghc }}-${{ hashFiles('**/package.yaml')
${{
runner.os
}}-cabal-${{
matrix.ghc
}}-${{
hashFiles('**/dist-newstyle/**/plan.json')
}}
restore-keys: |
${{ runner.os }}-cabal-${{ matrix.ghc }}-
- name: Update Cabal package index
run: cabal update
- name: Build project (GHC ${{ steps.setup-ghc.outputs.ghc-version }})
run: cabal build --project-file cabal.project.ci all
- name: Run tests (GHC ${{ steps.setup-ghc.outputs.ghc-version }})
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/future-proofing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
run: |
echo "GHC Version: ${{ steps.get-ghc.outputs.ghc-version }}"
echo "Cabal Store Path: ${{ steps.setup-ghc.outputs.cabal-store }}"
- name: Freeze and check dependencies
env:
CABAL_PROJECT: cabal.project.ci
shell: bash
run: bash ./.github/scripts/freeze_dependencies.sh
- name: Cache GHC, Cabal store, and build artifacts
uses: actions/cache@v4.3.0
with:
Expand All @@ -41,7 +46,7 @@ jobs:
${{ runner.os }}-cabal-${{
steps.get-ghc.outputs.ghc-version
}}-${{
hashFiles('**/package.yaml')
hashFiles('**/dist-newstyle/**/plan.json')
}}
restore-keys: |
${{ runner.os }}-cabal-${{ steps.get-ghc.outputs.ghc-version }}-
Expand Down
Loading