Skip to content

Commit 8790e03

Browse files
authored
Merge pull request #365 from HistoryAtState/fix-ci-lastmod
[WIP] Fix ci lastmod
2 parents 7d68277 + 4c68b2a commit 8790e03

File tree

5 files changed

+171
-96
lines changed

5 files changed

+171
-96
lines changed

.github/workflows/build.yml

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow builds a xar archive, deploys it into exist and execute a simple smoke test.
22
# It also includes code for using semantic-release to upload packages as part of GitHub releases
33
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
4-
# For node free automated release see https://trstringer.com/github-actions-create-release-upload-artifacts/
4+
# For node free automated release see https://trstringer.com/github-actions-create-release-upload-artifacts/
55

66
name: compile and test
77

@@ -11,26 +11,91 @@ jobs:
1111
build:
1212
runs-on: ubuntu-latest
1313
strategy:
14-
matrix:
15-
java-version: [11, 17]
14+
matrix:
15+
java-version: [11, 21]
1616

17-
1817
steps:
19-
# Checkout code
18+
# Checkout code fetch-depth significantly impacts performance
2019
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 15
2122
- name: Install Test Dependencies
2223
run: |
2324
sudo apt-get update
2425
sudo apt-get install -y libxml2-utils libsaxonhe-java
2526
2627
# - name: Where is Saxon
27-
# run: dpkg -L libsaxonhe-java
28+
# run: dpkg -L libsaxonhe-java
2829

2930
- name: Create Toc
3031
run: |
3132
mkdir -p frus-toc
3233
java -jar /usr/share/java/Saxon-HE.jar -s:volumes/ -xsl:modules/lib/frus-toc.xsl -o:frus-toc/ -it:main
33-
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+
3499
# sanity check
35100
- name: What happened
36101
run: git status
@@ -44,67 +109,67 @@ jobs:
44109
- name: Build Expath Package
45110
uses: actions/setup-java@v4
46111
with:
47-
distribution: 'temurin'
112+
distribution: "temurin"
48113
java-version: ${{ matrix.java-version }}
49114
- run: ant -Dapp.version=1.0.0-SNAPSHOT
50115

51116
- name: upload xar package
52-
if: ${{ matrix.java-version == 17 }}
117+
if: ${{ matrix.java-version == 21 }}
53118
uses: actions/upload-artifact@v4
54119
with:
55120
name: frus-xar
56121
path: build/*.xar
57122
if-no-files-found: ignore
58-
123+
59124
- name: upload smoke test
60-
if: ${{ matrix.java-version == 17 }}
125+
if: ${{ matrix.java-version == 21 }}
61126
uses: actions/upload-artifact@v4
62127
with:
63128
name: frus-bats
64129
path: tests/bats/
65130
if-no-files-found: ignore
66-
131+
67132
# Lint commit messages
68133
- name: lint commit message
69134
uses: wagoid/commitlint-github-action@v6
70135

71-
# Commit Toc files
136+
# Commit generated files
72137
- name: Commit and Push
73-
if: ${{ matrix.java-version == 17 && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
138+
if: ${{ matrix.java-version == 21 && github.event_name == 'push' && github.ref != 'refs/heads/master' }}
74139
uses: actions-x/commit@v6
75140
with:
76141
message: "fix(toc): update [skip ci]"
77142
test:
78143
runs-on: ubuntu-latest
79144
needs: build
80145
strategy:
81-
fail-fast: false
82-
matrix:
146+
fail-fast: false
147+
matrix:
83148
# 7.0.0-SNAPSHOT and 6.2.1 created
84-
exist-version: [release]
149+
exist-version: [release]
85150

86151
steps:
87152
- name: Maximize build space
88153
uses: easimon/maximize-build-space@master
89154
with:
90155
build-mount-path: /var/lib/docker/
91-
remove-dotnet: 'true'
92-
remove-android: 'true'
93-
remove-haskell: 'true'
94-
remove-codeql: 'true'
95-
remove-docker-images: 'true'
156+
remove-dotnet: "true"
157+
remove-android: "true"
158+
remove-haskell: "true"
159+
remove-codeql: "true"
160+
remove-docker-images: "true"
96161

97162
- name: Restart docker
98163
run: sudo service docker restart
99164

100165
- name: Set up Docker Buildx
101-
uses: docker/setup-buildx-action@v3
166+
uses: docker/setup-buildx-action@v3
102167

103168
- name: Install Test Dependencies
104169
run: |
105170
sudo apt-get update
106171
sudo apt-get install -y bats
107-
172+
108173
- name: create folders
109174
run: |
110175
mkdir build
@@ -114,28 +179,28 @@ jobs:
114179
with:
115180
name: frus-xar
116181
path: build
117-
182+
118183
- uses: actions/download-artifact@v4
119184
with:
120185
name: frus-bats
121186
path: tests/bats
122187

123-
# sanity check
188+
# sanity check
124189
- name: check os
125190
run: |
126191
df -h /var/lib/docker
127192
df -ih /var/lib/docker
128-
193+
129194
- name: Check config
130195
run: docker info
131-
196+
132197
# Install
133198
- name: Start exist-ci containers
134199
run: |
135200
docker run -dit -p 8080:8080 -v ${{ github.workspace }}/build:/exist/autodeploy \
136201
--name exist --rm \
137202
duncdrum/existdb:${{ matrix.exist-version }}
138-
203+
139204
- name: wait for install to finish
140205
timeout-minutes: 30
141206
run: |
@@ -146,7 +211,7 @@ jobs:
146211
# DEBUGGING
147212
- name: grab container logs
148213
if: always()
149-
run: docker cp exist:/exist/logs .
214+
run: docker cp exist:/exist/logs .
150215

151216
- uses: actions/upload-artifact@v4
152217
if: always()
@@ -159,7 +224,7 @@ jobs:
159224
if: always()
160225
run: rm -rf ./logs
161226

162-
# Test
227+
# Test
163228
- name: Run test
164229
run: bats --tap tests/bats/*.bats
165230

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ gitsha.xml
1515
node_modules/
1616
# Debug
1717
logs/
18+
.notes/

.releaserc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"preset": "conventionalcommits"
1212
}],
1313
["@semantic-release/exec", {
14-
"prepareCmd": "ant -Dapp.version=${nextRelease.version}"
14+
"prepareCmd": "ant -Dapp.version=${nextRelease.version} -Drelease=true"
1515
}],
1616
["@semantic-release/git", {
1717
"assets": ["expath-pkg.xml", "repo.xml"],

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,5 @@ more information, see <https://www.state.gov/copyright-information/#copyright>.
124124
```shell
125125
ant -Dapp.version=0.0.0-SNAPSHOT
126126
```
127+
128+
During a release the property `-Drelease=true` must be set for proper processing of template files.

0 commit comments

Comments
 (0)