Skip to content

Commit 6bf4d62

Browse files
committed
fix(ci): move file generation
to PR see #319
1 parent 2a1e10f commit 6bf4d62

File tree

4 files changed

+296
-95
lines changed

4 files changed

+296
-95
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -5,107 +5,57 @@
55

66
name: compile and test
77

8-
on: [push, pull_request]
8+
on:
9+
push:
10+
# branches-ignore:
11+
# - 'ref/pull/**'
12+
workflow_dispatch:
13+
14+
# concurrency:
15+
# group: lint-${{ github.event.pull_request.number || github.sha }}
16+
# cancel-in-progress: true
917

1018
jobs:
11-
build:
19+
lint:
1220
runs-on: ubuntu-latest
13-
strategy:
14-
matrix:
15-
java-version: [11, 21]
1621

1722
steps:
18-
# Checkout code fetch-depth significantly impacts performance
19-
- uses: actions/checkout@v4
20-
with:
21-
fetch-depth: 15
2223
- name: Install Test Dependencies
2324
run: |
2425
sudo apt-get update
25-
sudo apt-get install -y libxml2-utils libsaxonhe-java
26-
27-
# - name: Where is Saxon
28-
# run: dpkg -L libsaxonhe-java
26+
sudo apt-get install -y libxml2-utils
2927
30-
- name: Create Toc
31-
run: |
32-
mkdir -p frus-toc
33-
java -jar /usr/share/java/Saxon-HE.jar -s:volumes/ -xsl:modules/lib/frus-toc.xsl -o:frus-toc/ -it:main
34-
35-
- name: Get changed files
36-
id: changed-files
37-
run: |
38-
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
39-
40-
- name: Create xml files in .last-modified folder
41-
run: |
42-
for file in ${{ steps.changed-files.outputs.changed_files }}; do
43-
# Skip files in hidden folders (starting with .)
44-
if [[ "$file" =~ ^\..*/ ]]; then
45-
continue
46-
fi
47-
48-
if [ ! -f "$file" ]; then
49-
echo "Error: File '$file' does not exist" >&2
50-
return 1
51-
fi
52-
53-
# Get last commit date in ISO format
54-
if ! iso=$(git log -1 --format=%cd --date=format-local:'%Y-%m-%dT%H:%M:%S%z' "$file"); then
55-
echo "Error: Failed to get git log for '$file'" >&2
56-
return 1
57-
fi
58-
if ! datetime=$(git log -1 --format=%cd --date=iso-strict-local "$file"); then
59-
echo "Error: Failed to get git log for '$file'" >&2
60-
return 1
61-
fi
62-
63-
# Create output directory structure
64-
dir=$(dirname ".last-modified/$file")
65-
if ! mkdir -p "$dir"; then
66-
echo "Error: Failed to create directory '$dir'" >&2
67-
return 1
68-
fi
69-
70-
# Replace any forward slashes in path with underscores for xml:id
71-
xml_id=${file//\//0x2F}
72-
73-
# Convert date to seconds since epoch
74-
if [[ "$OSTYPE" == "darwin"* ]]; then
75-
if ! seconds_since_epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S%z" "$iso" "+%s"); then
76-
echo "Error: Failed to convert date for '$file'" >&2
77-
return 1
78-
fi
79-
else
80-
if ! seconds_since_epoch=$(date -d "$iso" +%s); then
81-
echo "Error: Failed to convert date for '$file'" >&2
82-
return 1
83-
fi
84-
fi
85-
86-
# Write XML files
87-
if ! echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > ".last-modified/$file"; then
88-
echo "Error: Failed to write XML header for '$file'" >&2
89-
return 1
90-
fi
91-
92-
if ! echo "<last-modified xml:id=\"$xml_id\" seconds_since_epoch=\"$seconds_since_epoch\">$datetime</last-modified>" >> ".last-modified/$file"; then
93-
echo "Error: Failed to write XML content for '$file'" >&2
94-
return 1
95-
fi
96-
echo "Successfully created .last-modified/$file"
97-
done
98-
99-
# sanity check
100-
- name: What happened
101-
run: git status
28+
# Checkout code fetch-depth significantly impacts performance
29+
- uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
10232

10333
# TODO(DP) Validate ?
10434
- name: Ensure all XML files are well-formed
10535
run: |
10636
xmllint --noout \
10737
$(find . -type f -name '*.xml')
10838
39+
# Lint commit messages
40+
- name: lint commit message
41+
uses: wagoid/commitlint-github-action@v6
42+
build:
43+
runs-on: ubuntu-latest
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
exist-version: [latest, release]
48+
java-version: [11, 21]
49+
exclude:
50+
- exist-version: release
51+
java-version: 21
52+
- exist-version: latest
53+
java-version: 11
54+
steps:
55+
- name: Checkout (sparse)
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 1
10959
- name: Build Expath Package
11060
uses: actions/setup-java@v4
11161
with:
@@ -129,16 +79,6 @@ jobs:
12979
path: tests/bats/
13080
if-no-files-found: ignore
13181

132-
# Lint commit messages
133-
- name: lint commit message
134-
uses: wagoid/commitlint-github-action@v6
135-
136-
# Commit generated files
137-
- name: Commit and Push
138-
if: ${{ matrix.java-version == 21 && github.event_name == 'push' && github.ref != 'refs/heads/master' }}
139-
uses: actions-x/commit@v6
140-
with:
141-
message: "fix(toc): update [skip ci]"
14282
test:
14383
runs-on: ubuntu-latest
14484
needs: build

.github/workflows/pr-dispatch.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: PR dispatch
2+
3+
on:
4+
pull_request:
5+
pull_request_target:
6+
types: [opened, synchronize, reopened]
7+
branches: ['main', 'master']
8+
workflow_call:
9+
10+
# concurrency:
11+
# group: dispatch-${{ github.event.pull_request.number || github.sha }}
12+
# cancel-in-progress: true
13+
14+
jobs:
15+
dispatch:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Check "Allow edits from maintainers" setting
19+
if: github.event.pull_request.head.repo.full_name != github.repository
20+
run: |
21+
if [ "${{ github.event.pull_request.maintainer_can_modify }}" = "true" ]; then
22+
echo "✅ PR is from a fork and 'Allow edits from maintainers' is ENABLED."
23+
else
24+
echo "⚠️ PR is from a fork and 'Allow edits from maintainers' is DISABLED."
25+
echo "ℹ️ Automated changes will fail. Enable the checkbox in the PR UI to allow CI to push changes."
26+
fi
27+
pr-internal:
28+
uses: ./.github/workflows/pr-internal.yml
29+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
30+
needs: dispatch
31+
secrets: inherit
32+
pr-external:
33+
uses: ./.github/workflows/pr-external.yml
34+
if: github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
35+
needs: dispatch
36+
secrets: inherit

.github/workflows/pr-external.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: exist-db External PR CI
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
external-pr-checks:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Install Test Dependencies
12+
run: |
13+
sudo apt-get update
14+
sudo apt-get install -y libsaxonhe-java
15+
16+
# Use ...head.ref for the full branch
17+
- name: Checkout PR head SHA
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
23+
- name: Fetch base commit (to allow diff)
24+
run: git fetch origin ${{ github.event.pull_request.base.sha }}
25+
26+
# - name: Where is Saxon
27+
# run: dpkg -L libsaxonhe-java
28+
29+
# add safe-branch checkout to generate an internal PR branch with generated files
30+
- name: Configure Git
31+
run: |
32+
git config user.name "ci-bot"
33+
git config user.email "ci-bot@example.com"
34+
35+
- name: Create ToC
36+
run: |
37+
mkdir -p frus-toc
38+
java -jar /usr/share/java/Saxon-HE.jar -s:volumes/ \
39+
-xsl:modules/lib/frus-toc.xsl -o:frus-toc/ -it:main
40+
41+
- name: Get changed files
42+
id: changed-files
43+
run: |
44+
echo "changed_files=$(git diff -r --name-only \
45+
${{ github.event.pull_request.base.sha }} \
46+
${{ github.event.pull_request.head.sha }} | xargs)" >> $GITHUB_OUTPUT
47+
48+
- name: Output changed files
49+
run: echo ${{ steps.changed-files.outputs.changed_files }}
50+
51+
- name: Create xml files in .last-modified folder
52+
run: |
53+
for file in ${{ steps.changed-files.outputs.changed_files }}; do
54+
# Skip files in hidden folders (starting with .)
55+
if [[ "$file" =~ ^\..*/ ]]; then
56+
continue
57+
fi
58+
59+
if [ ! -f "$file" ]; then
60+
echo "Error: File '$file' does not exist" >&2
61+
return 1
62+
fi
63+
64+
# Get last commit date in ISO format
65+
if ! iso=$(git log -1 --format=%cd --date=format-local:'%Y-%m-%dT%H:%M:%S%z' "$file"); then
66+
echo "Error: Failed to get git log for '$file'" >&2
67+
return 1
68+
fi
69+
if ! datetime=$(git log -1 --format=%cd --date=iso-strict-local "$file"); then
70+
echo "Error: Failed to get git log for '$file'" >&2
71+
return 1
72+
fi
73+
74+
# Create output directory structure
75+
dir=$(dirname ".last-modified/$file")
76+
if ! mkdir -p "$dir"; then
77+
echo "Error: Failed to create directory '$dir'" >&2
78+
return 1
79+
fi
80+
81+
# Replace any forward slashes in path with underscores for xml:id
82+
xml_id=${file//\//0x2F}
83+
84+
# Convert date to seconds since epoch
85+
if [[ "$OSTYPE" == "darwin"* ]]; then
86+
if ! seconds_since_epoch=$(date -j -f "%Y-%m-%dT%H:%M:%S%z" "$iso" "+%s"); then
87+
echo "Error: Failed to convert date for '$file'" >&2
88+
return 1
89+
fi
90+
else
91+
if ! seconds_since_epoch=$(date -d "$iso" +%s); then
92+
echo "Error: Failed to convert date for '$file'" >&2
93+
return 1
94+
fi
95+
fi
96+
97+
# Write XML files
98+
if ! echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > ".last-modified/$file"; then
99+
echo "Error: Failed to write XML header for '$file'" >&2
100+
return 1
101+
fi
102+
103+
if ! echo "<last-modified xml:id=\"$xml_id\" seconds_since_epoch=\"$seconds_since_epoch\">$datetime</last-modified>" >> ".last-modified/$file"; then
104+
echo "Error: Failed to write XML content for '$file'" >&2
105+
return 1
106+
fi
107+
echo "Successfully created .last-modified/$file"
108+
done
109+
110+
- name: Git commit/push to internal PR branch
111+
run: |
112+
git config user.name "ci-bot"
113+
git config user.email "ci-bot@example.com"
114+
git add --all
115+
git commit -m "fix(toc): auto-update [skip ci]" || echo "Nothing to commit"
116+
git push origin HEAD:${{ github.event.pull_request.head.ref }}

0 commit comments

Comments
 (0)