try first version withou host.json artifact
This commit is contained in:
parent
7f4987dc85
commit
63c3d4bec5
1 changed files with 41 additions and 159 deletions
|
|
@ -11,10 +11,10 @@ jobs:
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
outputs:
|
outputs:
|
||||||
changed: ${{ steps.changes.outputs.changed }}
|
changed: ${{ steps.changes.outputs.changed }}
|
||||||
hosts: ${{ steps.hosts.outputs.hosts || '[]' }}
|
hosts: ${{ steps.hosts.outputs.hosts }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: forgejo/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
|
@ -29,65 +29,19 @@ jobs:
|
||||||
- name: Check for changes
|
- name: Check for changes
|
||||||
id: changes
|
id: changes
|
||||||
run: |
|
run: |
|
||||||
echo "DEBUG: GITHUB_OUTPUT='${GITHUB_OUTPUT:-<unset>}'"
|
|
||||||
echo "DEBUG: Checking if GITHUB_OUTPUT var is set: $(if [ -z "${GITHUB_OUTPUT+x}" ]; then echo "NOT SET"; else echo "SET (value: '$GITHUB_OUTPUT')"; fi)"
|
|
||||||
|
|
||||||
set_output() {
|
|
||||||
echo "::set-output name=$1::$2"
|
|
||||||
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
|
||||||
echo "$1=$2" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
if git diff --quiet flake.lock; then
|
if git diff --quiet flake.lock; then
|
||||||
set_output changed false
|
echo "changed=false" >> $FORGEJO_OUTPUT
|
||||||
else
|
else
|
||||||
set_output changed true
|
echo "changed=true" >> $FORGEJO_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Extract LXC hosts
|
- name: Extract LXC hosts
|
||||||
id: 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)')
|
||||||
|
echo "hosts=$HOSTS" >> $FORGEJO_OUTPUT
|
||||||
set_output() {
|
|
||||||
echo "::set-output name=$1::$2"
|
|
||||||
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
|
||||||
echo "$1=$2" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
HOSTS=$(nix eval --json .#colmena --apply 'x: builtins.filter (n: n != "meta" && builtins.elem "lxc" (x.${n}.deployment.tags or [])) (builtins.attrNames x)') || {
|
|
||||||
echo "Failed to evaluate colmena hosts"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
# 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"
|
|
||||||
set_output hosts "[]"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
set_output hosts "$HOSTS"
|
|
||||||
echo "Discovered hosts: $HOSTS"
|
echo "Discovered hosts: $HOSTS"
|
||||||
# Also write to file as backup (in case job outputs don't work)
|
|
||||||
echo "$HOSTS" > hosts.json
|
|
||||||
# Debug output
|
|
||||||
echo "DEBUG: GITHUB_OUTPUT exists: ${GITHUB_OUTPUT:-NOT SET}"
|
|
||||||
if [ -n "${GITHUB_OUTPUT:-}" ] && [ -f "$GITHUB_OUTPUT" ]; then
|
|
||||||
echo "DEBUG: GITHUB_OUTPUT contents:"
|
|
||||||
cat "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Debug job outputs
|
|
||||||
if: steps.changes.outputs.changed == 'true'
|
|
||||||
run: |
|
|
||||||
echo "=== Step outputs ==="
|
|
||||||
echo "steps.changes.outputs.changed = '${{ steps.changes.outputs.changed }}'"
|
|
||||||
echo "steps.hosts.outputs.hosts = '${{ steps.hosts.outputs.hosts }}'"
|
|
||||||
echo "Length of hosts output: ${#HOSTS_OUT}"
|
|
||||||
env:
|
|
||||||
HOSTS_OUT: ${{ steps.hosts.outputs.hosts }}
|
|
||||||
|
|
||||||
- name: Upload flake.lock
|
- name: Upload flake.lock
|
||||||
if: steps.changes.outputs.changed == 'true'
|
if: steps.changes.outputs.changed == 'true'
|
||||||
|
|
@ -97,102 +51,42 @@ 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: ${{ fromJson(needs.check-updates.outputs.hosts) }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: forgejo/checkout@v4
|
||||||
|
|
||||||
- name: Download updated flake.lock
|
- name: Download updated flake.lock
|
||||||
uses: forgejo/download-artifact@v4
|
uses: forgejo/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: flake-lock
|
name: flake-lock
|
||||||
|
|
||||||
- name: Download hosts list
|
- name: Build ${{ matrix.host }}
|
||||||
uses: forgejo/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: hosts-list
|
|
||||||
|
|
||||||
- name: Build all hosts
|
|
||||||
id: build
|
id: build
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
echo "Building host: ${{ matrix.host }}"
|
||||||
|
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 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 logs
|
- name: Upload build log on failure
|
||||||
if: always()
|
if: failure() || steps.build.outcome == 'failure'
|
||||||
uses: forgejo/upload-artifact@v4
|
uses: forgejo/upload-artifact
|
||||||
with:
|
with:
|
||||||
name: build-logs
|
name: build-failure-${{ matrix.host }}
|
||||||
path: build-*.txt
|
path: build-output.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 "Some builds failed - check build-logs artifact"
|
echo "Build failed for ${{ matrix.host }}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -202,7 +96,7 @@ jobs:
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: forgejo/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
|
@ -216,48 +110,32 @@ jobs:
|
||||||
with:
|
with:
|
||||||
name: flake-lock
|
name: flake-lock
|
||||||
|
|
||||||
- name: Download build results
|
- name: Download failure artifacts
|
||||||
uses: forgejo/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: build-results
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Download hosts list
|
|
||||||
uses: forgejo/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: hosts-list
|
|
||||||
|
|
||||||
- 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:
|
||||||
name: build-logs
|
pattern: build-failure-*
|
||||||
path: logs
|
path: failures
|
||||||
|
merge-multiple: false
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- name: Create branch and commit
|
- name: Create branch and commit
|
||||||
id: branch
|
id: branch
|
||||||
run: |
|
run: |
|
||||||
set_output() {
|
|
||||||
echo "::set-output name=$1::$2"
|
|
||||||
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
|
||||||
echo "$1=$2" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
BRANCH_NAME="auto-update/$(date +%Y-%m-%d)"
|
BRANCH_NAME="auto-update/$(date +%Y-%m-%d)"
|
||||||
git checkout -b "$BRANCH_NAME"
|
git checkout -b "$BRANCH_NAME"
|
||||||
git add flake.lock
|
git add flake.lock
|
||||||
git commit -m "chore: update flake inputs $(date +%Y-%m-%d)"
|
git commit -m "chore: update flake inputs $(date +%Y-%m-%d)"
|
||||||
git push origin "$BRANCH_NAME"
|
git push origin "$BRANCH_NAME"
|
||||||
set_output branch_name "$BRANCH_NAME"
|
echo "branch_name=$BRANCH_NAME" >> $FORGEJO_OUTPUT
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
if: needs.build.result == 'success'
|
if: needs.build.result == 'success'
|
||||||
env:
|
env:
|
||||||
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
HOSTS=$(cat hosts.json)
|
HOSTS='${{ needs.check-updates.outputs.hosts }}'
|
||||||
HOST_LIST=$(echo "$HOSTS" | jq -r '.[] | "- " + .')
|
HOST_LIST=$(echo "$HOSTS" | jq -r '.[] | "- " + .' | tr '\n' '\n')
|
||||||
|
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-H "Authorization: token $FORGEJO_TOKEN" \
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
||||||
|
|
@ -275,22 +153,26 @@ 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=""
|
||||||
|
|
||||||
# Read failed hosts from build results
|
if [ -d "failures" ]; then
|
||||||
if [ -f "failed-hosts.txt" ]; then
|
for dir in failures/build-failure-*; do
|
||||||
for HOST in $(cat failed-hosts.txt); do
|
if [ -d "$dir" ]; then
|
||||||
FAILED_HOSTS="$FAILED_HOSTS\n- $HOST"
|
HOST=$(basename "$dir" | sed 's/build-failure-//')
|
||||||
|
FAILED_HOSTS="$FAILED_HOSTS\n- $HOST"
|
||||||
# Get build log if available
|
|
||||||
if [ -f "logs/build-${HOST}.txt" ]; then
|
if [ -f "$dir/build-output.txt" ]; then
|
||||||
LOG_TAIL=$(tail -50 "logs/build-${HOST}.txt" | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g')
|
# Get last 50 lines of build output
|
||||||
FAILURE_DETAILS="$FAILURE_DETAILS\n\n<details>\n<summary>$HOST build log (last 50 lines)</summary>\n\n\`\`\`\n$LOG_TAIL\n\`\`\`\n</details>"
|
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>"
|
||||||
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue