Skip to content

Add build comparison to GitHub Actions workflow #54

Add build comparison to GitHub Actions workflow

Add build comparison to GitHub Actions workflow #54

Workflow file for this run

name: build-site
on:
push:
branches:
tags:
paths-ignore:
- 'publisher/**'
- 'updater/**'
- '.github/workflows/ci-build-publisher.yml'
- '.github/workflows/ci-build-updater.yml'
- '.github/workflows/ci-frontend-check.yml'
- '.github/workflows/ci-frontend-lint.yml'
- '.github/dependabot.yml'
- '.github/FUNDING.yml'
- 'hugo/content/**' # content likely won't break the build
pull_request:
paths-ignore:
- 'publisher/**'
- 'updater/**'
- '.github/workflows/ci-build-publisher.yml'
- '.github/workflows/ci-build-updater.yml'
- '.github/workflows/ci-frontend-check.yml'
- '.github/workflows/ci-frontend-lint.yml'
- '.github/dependabot.yml'
- '.github/FUNDING.yml'
- 'hugo/content/**' # content likely won't break the build
jobs:
build:
name: build-and-compare
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed to fetch all history for comparison
- name: Get comparison commit
id: get-comparison-commit
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "compare_sha=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})" >> $GITHUB_OUTPUT
else
echo "compare_sha=$(git rev-parse HEAD^1)" >> $GITHUB_OUTPUT
fi
- name: Build previous version
run: |
git checkout ${{ steps.get-comparison-commit.outputs.compare_sha }}
docker build -t radio-t/site:previous .
docker run --rm -v ${{ github.workspace }}/public-prev:/srv/hugo/public radio-t/site:previous
- name: Build current version
run: |
git checkout ${{ github.event.pull_request.head.sha || github.sha }}
docker build -t radio-t/site:current .
docker run --rm -v ${{ github.workspace }}/public-current:/srv/hugo/public radio-t/site:current
- name: Generate diff
run: |
# Create a directory for the diff
mkdir -p site-diff
# Generate diff for HTML files
diff -r -N -u public-prev public-current > site-diff/changes.diff || true
# Generate a summary of changed files
echo "Changed files:" > site-diff/summary.txt
find public-current -type f -exec sh -c '
prev_file="public-prev/${1#public-current/}"
if [ ! -f "$prev_file" ]; then
echo "New: ${1#public-current/}"
elif ! cmp -s "$1" "$prev_file"; then
echo "Modified: ${1#public-current/}"
fi
' sh {} \; >> site-diff/summary.txt
find public-prev -type f -exec sh -c '
current_file="public-current/${1#public-prev/}"
if [ ! -f "$current_file" ]; then
echo "Deleted: ${1#public-prev/}"
fi
' sh {} \; >> site-diff/summary.txt
- name: Upload diff artifacts
uses: actions/upload-artifact@v4
with:
name: site-diff
path: site-diff/