Forgejo Actions #5
2 changed files with 110 additions and 109 deletions
|
|
@ -11,7 +11,6 @@ jobs:
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
outputs:
|
outputs:
|
||||||
changed: ${{ steps.changes.outputs.changed }}
|
changed: ${{ steps.changes.outputs.changed }}
|
||||||
hosts: ${{ steps.hosts.outputs.hosts }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
@ -20,7 +19,7 @@ jobs:
|
||||||
|
|
||||||
- name: Configure Git
|
- name: Configure Git
|
||||||
run: |
|
run: |
|
||||||
git config user.name "Flake Update Bot"
|
git config user.name "Flake Update Bot"
|
||||||
git config user.email "bot@noreply.local"
|
git config user.email "bot@noreply.local"
|
||||||
|
|
||||||
- name: Update flake inputs
|
- name: Update flake inputs
|
||||||
|
|
@ -36,11 +35,18 @@ jobs:
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Extract LXC hosts
|
- name: Extract LXC hosts
|
||||||
id: hosts
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
if: steps.changes.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
HOSTS=$(nix eval --json .#colmena --apply 'x: builtins.filter (n: n != "meta" && builtins.elem "lxc" (x.${n}.deployment.tags or [])) (builtins.attrNames x)')
|
HOSTS=$(nix eval --json .#colmena --apply 'x: builtins.filter (n: n != "meta" && builtins.elem "lxc" (x.${n}.deployment.tags or [])) (builtins.attrNames x)')
|
||||||
echo "hosts=$HOSTS" >> $FORGEJO_OUTPUT
|
|
||||||
|
# Validate the output is a non-empty JSON array
|
||||||
|
if ! echo "$HOSTS" | jq -e '. | if type == "array" and length > 0 then true else false end' > /dev/null 2>&1; then
|
||||||
|
echo "Error: No LXC hosts found or invalid JSON output: $HOSTS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$HOSTS" > hosts.json
|
||||||
echo "Discovered hosts: $HOSTS"
|
echo "Discovered hosts: $HOSTS"
|
||||||
|
|
||||||
- name: Upload flake.lock
|
- name: Upload flake.lock
|
||||||
|
|
@ -51,19 +57,19 @@ jobs:
|
||||||
path: flake.lock
|
path: flake.lock
|
||||||
retention-days: 1
|
retention-days: 1
|
||||||
|
|
||||||
|
- name: Upload hosts list
|
||||||
|
if: steps.changes.outputs.changed == 'true'
|
||||||
|
uses: forgejo/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: hosts-list
|
||||||
|
path: hosts.json
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: check-updates
|
needs: check-updates
|
||||||
if: needs.check-updates.outputs.changed == 'true'
|
if: needs.check-updates.outputs.changed == 'true'
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
host: ${{ needs.check-updates.outputs.hosts }}
|
|
||||||
steps:
|
steps:
|
||||||
- name: Debug HOSTS
|
|
||||||
run: |
|
|
||||||
echo "HOSTS: "${{ needs.check-updates.outputs.hosts }}
|
|
||||||
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|
@ -72,25 +78,81 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: flake-lock
|
name: flake-lock
|
||||||
|
|
||||||
- name: Build ${{ matrix.host }}
|
- name: Download hosts list
|
||||||
|
uses: forgejo/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: hosts-list
|
||||||
|
|
||||||
|
- name: Build all hosts
|
||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
echo "Building host: ${{ matrix.host }}"
|
set -euo pipefail
|
||||||
nix build .#nixosConfigurations.${{ matrix.host }}.config.system.build.toplevel --no-link 2>&1 | tee build-output.txt
|
|
||||||
|
if [ ! -f hosts.json ]; then
|
||||||
|
echo "Error: hosts.json not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
HOSTS=$(cat hosts.json)
|
||||||
|
echo "Building hosts: $HOSTS"
|
||||||
|
|
||||||
|
FAILED_HOSTS=""
|
||||||
|
SUCCESS_HOSTS=""
|
||||||
|
|
||||||
|
for HOST in $(echo "$HOSTS" | jq -r '.[]'); do
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "Building: $HOST"
|
||||||
|
echo "=========================================="
|
||||||
|
|
||||||
|
if nix build ".#nixosConfigurations.${HOST}.config.system.build.toplevel" --no-link --quiet 2>&1 | tee "build-${HOST}.txt"; then
|
||||||
|
echo "✓ Build succeeded: $HOST"
|
||||||
|
SUCCESS_HOSTS="$SUCCESS_HOSTS $HOST"
|
||||||
|
else
|
||||||
|
echo "✗ Build failed: $HOST"
|
||||||
|
FAILED_HOSTS="$FAILED_HOSTS $HOST"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=========================================="
|
||||||
|
echo "Build Summary"
|
||||||
|
echo "=========================================="
|
||||||
|
echo "Succeeded:$SUCCESS_HOSTS"
|
||||||
|
echo "Failed:$FAILED_HOSTS"
|
||||||
|
|
||||||
|
# Save results for report job
|
||||||
|
echo "$FAILED_HOSTS" > failed-hosts.txt
|
||||||
|
echo "$SUCCESS_HOSTS" > success-hosts.txt
|
||||||
|
|
||||||
|
if [ -n "$FAILED_HOSTS" ]; then
|
||||||
|
echo "Some builds failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Upload build log on failure
|
- name: Upload build logs
|
||||||
if: failure() || steps.build.outcome == 'failure'
|
if: always()
|
||||||
uses: forgejo/upload-artifact@v4
|
uses: forgejo/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: build-failure-${{ matrix.host }}
|
name: build-logs
|
||||||
path: build-output.txt
|
path: build-*.txt
|
||||||
retention-days: 7
|
retention-days: 7
|
||||||
|
|
||||||
|
- name: Upload build results
|
||||||
|
if: always()
|
||||||
|
uses: forgejo/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-results
|
||||||
|
path: |
|
||||||
|
failed-hosts.txt
|
||||||
|
success-hosts.txt
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
- name: Check build result
|
- name: Check build result
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ steps.build.outcome }}" == "failure" ]; then
|
if [ "${{ steps.build.outcome }}" == "failure" ]; then
|
||||||
echo "Build failed for ${{ matrix.host }}"
|
echo "Some builds failed - check build-logs artifact"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -114,13 +176,23 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: flake-lock
|
name: flake-lock
|
||||||
|
|
||||||
- name: Download failure artifacts
|
- name: Download hosts list
|
||||||
|
uses: forgejo/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: hosts-list
|
||||||
|
|
||||||
|
- name: Download build results
|
||||||
|
uses: forgejo/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: build-results
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Download build logs
|
||||||
if: needs.build.result == 'failure'
|
if: needs.build.result == 'failure'
|
||||||
uses: forgejo/download-artifact@v4
|
uses: forgejo/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
pattern: build-failure-*
|
name: build-logs
|
||||||
path: failures
|
path: logs
|
||||||
merge-multiple: false
|
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Create branch and commit
|
- name: Create branch and commit
|
||||||
|
|
@ -138,8 +210,8 @@ jobs:
|
||||||
env:
|
env:
|
||||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
HOSTS='${{ needs.check-updates.outputs.hosts }}'
|
HOSTS=$(cat hosts.json)
|
||||||
HOST_LIST=$(echo "$HOSTS" | jq -r '.[] | "- " + .' | tr '\n' '\n')
|
HOST_LIST=$(echo "$HOSTS" | jq -r '.[] | "- " + .')
|
||||||
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
|
@ -157,31 +229,27 @@ jobs:
|
||||||
env:
|
env:
|
||||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
# Collect failed hosts from artifact directories
|
|
||||||
FAILED_HOSTS=""
|
FAILED_HOSTS=""
|
||||||
FAILURE_DETAILS=""
|
FAILURE_DETAILS=""
|
||||||
|
|
||||||
if [ -d "failures" ]; then
|
# Read failed hosts from build results
|
||||||
for dir in failures/build-failure-*; do
|
if [ -f "failed-hosts.txt" ]; then
|
||||||
if [ -d "$dir" ]; then
|
for HOST in $(cat failed-hosts.txt); do
|
||||||
HOST=$(basename "$dir" | sed 's/build-failure-//')
|
FAILED_HOSTS="$FAILED_HOSTS\n- $HOST"
|
||||||
FAILED_HOSTS="$FAILED_HOSTS\n- $HOST"
|
|
||||||
|
# Get build log if available
|
||||||
if [ -f "$dir/build-output.txt" ]; then
|
if [ -f "logs/build-${HOST}.txt" ]; then
|
||||||
# Get last 50 lines of build output
|
LOG_TAIL=$(tail -50 "logs/build-${HOST}.txt" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
|
||||||
LOG_TAIL=$(tail -50 "$dir/build-output.txt" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
|
FAILURE_DETAILS="$FAILURE_DETAILS\n\n<details>\n<summary>$HOST build log (last 50 lines)</summary>\n\n\`\`\`\n$LOG_TAIL\n\`\`\`\n</details>"
|
||||||
FAILURE_DETAILS="$FAILURE_DETAILS\n\n<details>\n<summary>$HOST build log (last 50 lines)</summary>\n\n\`\`\`\n$LOG_TAIL\n\`\`\`\n</details>"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If no failure artifacts found, list from matrix
|
|
||||||
if [ -z "$FAILED_HOSTS" ]; then
|
if [ -z "$FAILED_HOSTS" ]; then
|
||||||
FAILED_HOSTS="\n- (Unable to determine failed hosts - check workflow logs)"
|
FAILED_HOSTS="\n- (Unable to determine failed hosts - check workflow logs)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ISSUE_BODY="Weekly flake update failed to build some hosts.\n\n**Branch:** \`${{ steps.branch.outputs.branch_name }}\`\n**Run:** ${{ forge.server_url }}/${{ forge.repository }}/actions/runs/${{ forge.run_number }}\n\n**Failed hosts:**$FAILED_HOSTS\n$FAILURE_DETAILS\n\nGenerated on: $(date -Iseconds)"
|
ISSUE_BODY="Weekly flake update failed to build some hosts.\n\n**Branch:** \`${{ steps.branch.outputs.branch_name }}\`\n**Run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n\n**Failed hosts:**$FAILED_HOSTS\n$FAILURE_DETAILS\n\nGenerated on: $(date -Iseconds)"
|
||||||
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
|
@ -190,10 +258,10 @@ jobs:
|
||||||
\"title\": \"Build failure: weekly flake update $(date +%Y-%m-%d)\",
|
\"title\": \"Build failure: weekly flake update $(date +%Y-%m-%d)\",
|
||||||
\"body\": \"$ISSUE_BODY\"
|
\"body\": \"$ISSUE_BODY\"
|
||||||
}" \
|
}" \
|
||||||
"${{ forge.server_url }}/api/v1/repos/${{ forge.repository }}/issues"
|
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/issues"
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
nix-collect-garbage -d
|
nix-collect-garbage -d
|
||||||
rm -rf result .direnv failures
|
rm -rf result .direnv logs
|
||||||
|
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
name: shared matrix
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
test:
|
|
||||||
runs-on: nix
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
variant: ['bookworm', 'bullseye']
|
|
||||||
node: ['18', '20']
|
|
||||||
steps:
|
|
||||||
- uses: https://code.forgejo.org/actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '${{ matrix.node }}'
|
|
||||||
|
|
||||||
define-matrix:
|
|
||||||
runs-on: nix
|
|
||||||
|
|
||||||
outputs:
|
|
||||||
colors: ${{ steps.colors.outputs.colors }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Define Colors
|
|
||||||
id: colors
|
|
||||||
run: |
|
|
||||||
echo 'colors=["red", "green", "blue"]' >> "$FORGEJO_OUTPUT"
|
|
||||||
|
|
||||||
produce-artifacts:
|
|
||||||
runs-on: nix
|
|
||||||
needs: define-matrix
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
color: ${{ fromJSON(needs.define-matrix.outputs.colors) }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Define Color
|
|
||||||
env:
|
|
||||||
color: ${{ matrix.color }}
|
|
||||||
run: |
|
|
||||||
echo "$color" > color
|
|
||||||
- name: Produce Artifact
|
|
||||||
uses: forgejo/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.color }}
|
|
||||||
path: color
|
|
||||||
|
|
||||||
consume-artifacts:
|
|
||||||
runs-on: nix
|
|
||||||
needs:
|
|
||||||
- define-matrix
|
|
||||||
- produce-artifacts
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
color: ${{ fromJSON(needs.define-matrix.outputs.colors) }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Retrieve Artifact
|
|
||||||
uses: forgejo/download-artifact@v5
|
|
||||||
with:
|
|
||||||
name: ${{ matrix.color }}
|
|
||||||
|
|
||||||
- name: Report Color
|
|
||||||
run: |
|
|
||||||
cat color
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue