Skip to content

Commit

Permalink
Add build comparison to GitHub Actions workflow
Browse files Browse the repository at this point in the history
Include steps to compare current code with previous commit using Docker builds. Generate a diff for HTML files and upload artifacts for review.
  • Loading branch information
paskal committed Nov 1, 2024
1 parent 28582f4 commit 9579a3e
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions .github/workflows/ci-build-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,63 @@ on:

jobs:
build:
name: 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: check out code
uses: actions/checkout@v4
- 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 site image
run: docker build -t radio-t/site .
- 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/

0 comments on commit 9579a3e

Please sign in to comment.