Skip to content

Commit 529c32f

Browse files
Refactor: Optimize GitHub Actions workflows for efficiency
This commit introduces several optimizations to the GitHub Actions workflows to reduce build times and improve overall efficiency. Key changes include: 1. **Pacman Caching (`build.yml`, `validate-build.yaml`):** - Implemented content-aware cache keys for Pacman packages using `hashFiles` on `packages.x86_64`, `bootstrap_packages.x86_64`, and `pacman.conf`. This ensures the cache is used more effectively and invalidated only when relevant package definitions change. 2. **Docker Build Optimization (`dockerfile`):** - Refactored the `dockerfile` to create a much leaner final image. - The `final` stage now only copies the `entrypoint.sh` script, relying on the CI environment to mount the workspace for build files. - This significantly improves Docker layer caching and reduces the final image size. 3. **Release Notes Streamlining (`build.yml`, `release-notes.yml`):** - Consolidated all release note generation logic into `build.yml`. - The `build.yml` workflow now generates a comprehensive changelog, including categorized commit history between releases, in addition to package update information. - The separate `release-notes.yml` workflow has been removed, simplifying the release process. 4. **Validation Enhancement (`validate-build.yaml`):** - Added detailed ISO verification (file count, size, SHA256 checksum) to the `dockerfile-build` matrix leg in `validate-build.yaml`. - This ensures that ISOs produced by the Dockerized build method (the primary method) are validated to the same standards as those from the `direct-build` method. 5. **Conditional Scheduled Execution (`validate-build.yaml`):** - Implemented logic to skip scheduled runs of `validate-build.yaml` if no new commits have been pushed to the `main` branch since the last successful scheduled validation. - This is achieved by using a dedicated git tag (`last-validated-main-sha`) to store the SHA of the last validated commit. - Workflow permissions were updated to allow tag pushing. These changes aim to make the CI/CD processes faster, more resource-efficient, and more robust.
1 parent b5c0a20 commit 529c32f

File tree

4 files changed

+219
-138
lines changed

4 files changed

+219
-138
lines changed

.github/workflows/build.yml

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
steps:
2424
- name: Checkout Repository
2525
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0 # Fetch all history for all branches and tags
2628

2729
- name: Setup Environment
2830
run: |
@@ -35,9 +37,10 @@ jobs:
3537
uses: actions/cache@v4
3638
with:
3739
path: ${{ env.PACMAN_CACHE }}
38-
key: archlinux-pacman-${{ github.run_id }}
40+
key: archlinux-pacman-v2-${{ runner.os }}-${{ hashFiles('packages.x86_64', 'bootstrap_packages.x86_64', 'pacman.conf') }}
3941
restore-keys: |
40-
archlinux-pacman-
42+
archlinux-pacman-v2-${{ runner.os }}-
43+
archlinux-pacman-v2-
4144
4245
- name: Set up Docker Container
4346
run: |
@@ -134,6 +137,76 @@ jobs:
134137
# Ensure DETAILED_RELEASE_NOTES.md is created
135138
cp release_notes.md DETAILED_RELEASE_NOTES.md
136139
140+
- name: Generate Detailed Changelog
141+
id: generate_detailed_changelog
142+
run: |
143+
echo "Starting detailed changelog generation..."
144+
CURRENT_TAG="${{ env.RELEASE_TAG }}"
145+
echo "Current tag for release: $CURRENT_TAG"
146+
147+
# Fetch all tags from remote to ensure we have the latest state
148+
git fetch --tags
149+
150+
# Determine PREVIOUS_TAG
151+
# Exclude the current tag from the list of potential previous tags
152+
# Sort tags in descending order (v:refname for version sort)
153+
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -v "^$CURRENT_TAG$" | head -n1 || echo "")
154+
155+
if [ -z "$PREVIOUS_TAG" ]; then
156+
echo "No previous tag found or it's the first release. Changelog will be from the beginning of history."
157+
# Use --reverse to list oldest first for better readability in release notes
158+
COMMITS=$(git log --pretty=format:"- %s (%h) by @%an" --reverse HEAD)
159+
else
160+
echo "Generating changelog from $PREVIOUS_TAG to $CURRENT_TAG (effectively HEAD)"
161+
# Use --reverse to list oldest first
162+
COMMITS=$(git log --pretty=format:"- %s (%h) by @%an" --reverse $PREVIOUS_TAG..HEAD)
163+
fi
164+
165+
if [ -z "$COMMITS" ]; then
166+
echo "No commits found for the range. Setting a default message."
167+
COMMITS="No specific code changes identified in this release."
168+
fi
169+
170+
CHANGELOG_DETAILS_FILE="changelog_details.md"
171+
echo "Generating changelog details into $CHANGELOG_DETAILS_FILE..."
172+
{
173+
echo ""
174+
echo "---"
175+
echo ""
176+
echo "## 📋 Detailed Changes from Git Log"
177+
echo ""
178+
echo "### 🚀 Features & Enhancements"
179+
echo "$COMMITS" | grep -i -E 'feat|feature|add|enhance|implement' || echo "_No specific features/enhancements in this update based on commit messages._"
180+
echo ""
181+
echo "### 🐛 Bug Fixes"
182+
echo "$COMMITS" | grep -i -E 'fix|bug|issue|problem|resolve' || echo "_No specific bug fixes in this update based on commit messages._"
183+
echo ""
184+
echo "### 🔧 Maintenance & Refactoring"
185+
echo "$COMMITS" | grep -i -E 'refactor|chore|docs|test|ci|build|perf|style' || echo "_No specific maintenance/refactoring in this update based on commit messages._"
186+
echo ""
187+
echo "### 📝 Other Changes"
188+
# The OR condition ensures that if grep finds nothing, it still prints the fallback message.
189+
# This grep looks for lines NOT matching the previous categories.
190+
echo "$COMMITS" | grep -v -i -E 'feat|feature|add|enhance|implement|fix|bug|issue|problem|resolve|refactor|chore|docs|test|ci|build|perf|style' || echo "_No other specific changes in this update based on commit messages._"
191+
# If COMMITS was the default "No specific code changes..." message, the above grep -v would still output it.
192+
# We add a specific check here to ensure if COMMITS was "No specific code changes...", it's handled gracefully by "Other Changes"
193+
if [ "$COMMITS" = "No specific code changes identified in this release." ]; then
194+
echo "$COMMITS"
195+
fi
196+
echo ""
197+
echo "---"
198+
if [ -n "$PREVIOUS_TAG" ]; then
199+
echo "📦 Full commit history: [$PREVIOUS_TAG...${CURRENT_TAG} (HEAD)](https://github.com/${{ github.repository }}/compare/$PREVIOUS_TAG...${{ github.sha }})"
200+
else
201+
echo "📦 Full commit history up to this release: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})"
202+
fi
203+
} > "$CHANGELOG_DETAILS_FILE"
204+
205+
echo "Appending $CHANGELOG_DETAILS_FILE to DETAILED_RELEASE_NOTES.md"
206+
cat "$CHANGELOG_DETAILS_FILE" >> DETAILED_RELEASE_NOTES.md
207+
rm -f "$CHANGELOG_DETAILS_FILE" # Clean up temp file
208+
echo "Detailed changelog generation complete."
209+
137210
- name: Create GitHub Release
138211
uses: softprops/action-gh-release@v2
139212
with:

.github/workflows/release-notes.yml

Lines changed: 0 additions & 115 deletions
This file was deleted.

.github/workflows/validate-build.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
schedule:
1010
- cron: '0 0 * * *' # Run daily checks
1111

12+
permissions:
13+
contents: write # Needed to push tags
14+
1215
env:
1316
DOCKER_BUILDKIT: 1
1417
PACMAN_CACHE: /tmp/pacman-cache
@@ -17,7 +20,47 @@ env:
1720
OUTPUT_DIR: /workdir/out
1821

1922
jobs:
23+
check_changes:
24+
if: github.event_name == 'schedule' # Only run this check for scheduled triggers
25+
runs-on: ubuntu-latest
26+
outputs:
27+
should_run: ${{ steps.compare_sha.outputs.should_run }}
28+
steps:
29+
- name: Checkout main branch code
30+
uses: actions/checkout@v4
31+
with:
32+
ref: main # Explicitly checkout main
33+
fetch-depth: 0 # Needed for tags and full history
34+
35+
- name: Define Tag Name
36+
id: tag_info
37+
run: echo "tag_name=last-validated-main-sha" >> $GITHUB_OUTPUT
38+
39+
- name: Get last validated SHA and current main SHA
40+
id: compare_sha
41+
run: |
42+
TAG_NAME="${{ steps.tag_info.outputs.tag_name }}"
43+
# Fetch tags from remote to ensure we have the latest
44+
git fetch --tags origin
45+
46+
LAST_VALIDATED_SHA=$(git rev-parse --verify "$TAG_NAME" 2>/dev/null || echo "")
47+
# Get SHA of the local main branch HEAD (already checked out)
48+
CURRENT_MAIN_SHA=$(git rev-parse HEAD)
49+
50+
echo "Last validated SHA ($TAG_NAME): $LAST_VALIDATED_SHA"
51+
echo "Current main SHA (HEAD of main): $CURRENT_MAIN_SHA"
52+
53+
if [ -n "$LAST_VALIDATED_SHA" ] && [ "$LAST_VALIDATED_SHA" == "$CURRENT_MAIN_SHA" ]; then
54+
echo "No new commits on main since last validation."
55+
echo "should_run=false" >> $GITHUB_OUTPUT
56+
else
57+
echo "New commits found or first run. Proceeding with validation."
58+
echo "should_run=true" >> $GITHUB_OUTPUT
59+
fi
60+
2061
test:
62+
needs: [check_changes]
63+
if: ${{ github.event_name != 'schedule' || needs.check_changes.outputs.should_run == 'true' }}
2164
runs-on: ubuntu-latest
2265
timeout-minutes: 120 # Set timeout to prevent hung builds
2366

@@ -49,6 +92,16 @@ jobs:
4992
-v ${{ env.PACMAN_CACHE }}:/var/cache/pacman/pkg \
5093
archlinux:latest sleep infinity
5194
95+
- name: Cache Pacman packages (Direct Build)
96+
if: matrix.test-type == 'direct-build'
97+
uses: actions/cache@v4
98+
with:
99+
path: ${{ env.PACMAN_CACHE }}
100+
key: archlinux-pacman-v2-${{ runner.os }}-${{ hashFiles('packages.x86_64', 'bootstrap_packages.x86_64', 'pacman.conf') }}
101+
restore-keys: |
102+
archlinux-pacman-v2-${{ runner.os }}-
103+
archlinux-pacman-v2-
104+
52105
- name: Install Dependencies (Direct Build)
53106
if: matrix.test-type == 'direct-build'
54107
run: |
@@ -160,6 +213,79 @@ jobs:
160213
ls -la out
161214
fi
162215
216+
- name: Verify ISO (Dockerfile Build)
217+
if: matrix.test-type == 'dockerfile-build'
218+
run: |
219+
set -euo pipefail
220+
cd out # The ISO is built into the 'out' directory in the workspace
221+
222+
echo "Listing contents of 'out' directory:"
223+
ls -la
224+
225+
# Check if ISO exists
226+
iso_count=$(ls -1 *.iso 2>/dev/null | wc -l)
227+
if [ "$iso_count" -eq 0 ]; then
228+
echo "::error::No ISO file found in output directory"
229+
exit 1
230+
elif [ "$iso_count" -gt 1 ]; then
231+
echo "::error::Multiple ISO files found in output directory. Expected one."
232+
ls -1 *.iso # List the files to help debug
233+
exit 1
234+
fi
235+
236+
update_last_validated_tag:
237+
if: github.event_name == 'schedule' && needs.check_changes.outputs.should_run == 'true' && needs.test.result == 'success'
238+
needs: [check_changes, test] # Depends on both
239+
runs-on: ubuntu-latest
240+
steps:
241+
- name: Checkout main branch code
242+
uses: actions/checkout@v4
243+
with:
244+
ref: main # Ensure we are on main to get its SHA
245+
246+
- name: Define Tag Name
247+
id: tag_info
248+
run: echo "tag_name=last-validated-main-sha" >> $GITHUB_OUTPUT
249+
250+
- name: Update and Push Tag
251+
run: |
252+
TAG_NAME="${{ steps.tag_info.outputs.tag_name }}"
253+
CURRENT_MAIN_SHA=$(git rev-parse HEAD) # SHA of local main HEAD
254+
255+
echo "Updating tag $TAG_NAME to $CURRENT_MAIN_SHA"
256+
git tag -f "$TAG_NAME" "$CURRENT_MAIN_SHA"
257+
echo "Pushing tag $TAG_NAME to origin"
258+
git push origin --force "refs/tags/$TAG_NAME"
259+
260+
iso_file=$(ls *.iso | head -n1)
261+
echo "Verifying ISO: $iso_file"
262+
263+
# Check ISO size (minimum 500MB) - adjust if necessary
264+
size=$(stat -c%s "$iso_file")
265+
# Minimum size in bytes (500 * 1024 * 1024)
266+
MIN_SIZE=524288000
267+
if [ "$size" -lt "$MIN_SIZE" ]; then
268+
echo "::error::ISO file too small: $(($size / 1024 / 1024))MB. Minimum expected: $(($MIN_SIZE / 1024 / 1024))MB"
269+
exit 1
270+
fi
271+
echo "ISO size: $(($size / 1024 / 1024))MB - OK"
272+
273+
# Verify ISO checksum (SHA256)
274+
echo "Generating and verifying SHA256 checksum..."
275+
sha256sum "$iso_file" > "${iso_file}.sha256"
276+
sha256sum -c "${iso_file}.sha256" || {
277+
echo "::error::ISO SHA256 checksum verification failed"
278+
exit 1
279+
}
280+
echo "SHA256 checksum verified."
281+
282+
# Optionally, generate other checksums (can be useful for users)
283+
echo "Generating MD5 checksum..."
284+
md5sum "$iso_file" > "${iso_file}.md5"
285+
echo "Generating SHA1 checksum..."
286+
sha1sum "$iso_file" > "${iso_file}.sha1"
287+
echo "Additional checksums (MD5, SHA1) generated."
288+
163289
# Cleanup for Dockerfile build
164290
- name: Clean Up Dockerfile Build
165291
if: matrix.test-type == 'dockerfile-build' && always()

0 commit comments

Comments
 (0)