-
-
Notifications
You must be signed in to change notification settings - Fork 0
+ automatically refresh README screenshots #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Generate | ||
|
|
||
| # Cheap generation stage: every push to a working branch refreshes derived files and commits them | ||
| # straight back onto that branch. By the time the pull request runs its full CI battery, the README | ||
| # screenshots are already part of the branch rather than being CI-only artifacts. | ||
| # | ||
| # Never on main: that branch takes changes through pull requests only, and the shared action refuses | ||
| # to touch the default branch as an additional guard. | ||
| on: | ||
| push: | ||
| branches-ignore: [main] | ||
| workflow_dispatch: {} | ||
|
|
||
| permissions: | ||
| actions: write | ||
| contents: write | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: generate-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true' | ||
|
|
||
| jobs: | ||
| screenshots: | ||
| name: refresh README screenshots | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-dotnet@v4 | ||
| with: | ||
| dotnet-version: '8.x' | ||
|
|
||
| - name: Clone sibling CompressionWorkbench | ||
| shell: bash | ||
| run: git clone --depth 1 https://github.com/Hawkynt/CompressionWorkbench.git "$GITHUB_WORKSPACE/../CompressionWorkbench" | ||
|
|
||
| - name: Generate README screenshots | ||
| env: | ||
| PHOTOMANAGER_CAPTURE_SCREENSHOTS: '1' | ||
| run: > | ||
| dotnet test PhotoManager.Tests/PhotoManager.Tests.csproj | ||
| --configuration Release | ||
| --filter Category=Screenshot | ||
|
|
||
| - name: Validate generated screenshots | ||
| shell: bash | ||
| run: | | ||
| for screenshot in screenshots/main-window.png screenshots/develop-window.png; do | ||
| test -s "$screenshot" | ||
| signature=$(od -An -tx1 -N8 "$screenshot" | tr -d ' \n') | ||
| if [ "$signature" != "89504e470d0a1a0a" ]; then | ||
| echo "::error::$screenshot is not a PNG file." | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Commit refreshed main window screenshot | ||
| uses: Hawkynt/RepositoryTemplate/commit-generated-file@v1 | ||
| with: | ||
| file: screenshots/main-window.png | ||
| message: '* refresh the main window screenshot' | ||
|
|
||
| - name: Commit refreshed develop window screenshot | ||
| uses: Hawkynt/RepositoryTemplate/commit-generated-file@v1 | ||
| with: | ||
| file: screenshots/develop-window.png | ||
| message: '* refresh the develop window screenshot' | ||
|
|
||
| # GITHUB_TOKEN updates to an already-open PR intentionally create an approval-required | ||
| # pull_request/synchronize run. workflow_dispatch is the documented exception that may start | ||
| # another workflow with GITHUB_TOKEN, so dispatch CI explicitly when generation actually | ||
| # advanced a branch that already belongs to an open PR. | ||
| - name: Run CI on the generated head | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| branch="$GITHUB_REF_NAME" | ||
| generated_head=$(gh api "repos/$GITHUB_REPOSITORY/branches/$branch" --jq '.commit.sha') | ||
| if [ "$generated_head" = "$GITHUB_SHA" ]; then | ||
| echo "::notice::The screenshots were already current; the normal PR synchronize run covers this head." | ||
| exit 0 | ||
| fi | ||
|
|
||
| owner="${GITHUB_REPOSITORY%%/*}" | ||
| open_prs=$(gh api --method GET "repos/$GITHUB_REPOSITORY/pulls" \ | ||
| -f state=open -f head="$owner:$branch" --jq 'length') | ||
| if [ "$open_prs" -eq 0 ]; then | ||
| echo "::notice::No open pull request for $branch; keeping generation as the cheap pre-PR stage." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Dispatching CI for generated head $generated_head." | ||
| gh workflow run ci.yml --ref "$branch" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On branches containing
/—for example, the commonfeature/screenshotsnaming pattern—gh apisends this interpolated value as multiple URL path segments, while GitHub's Get a branch endpoint expects the branch name as one encoded path parameter. The lookup therefore returns 404 and the Generate job fails before it can dispatch CI; if screenshots were committed withGITHUB_TOKEN, that generated head receives no automatic CI run. Percent-encodebranchbefore constructing this endpoint or obtain the head SHA without embedding the raw ref in the path;gh api --helplikewise describes placeholder substitution, not automatic encoding of manually interpolated endpoint components (CLI manual).Useful? React with 👍 / 👎.