Skip to content

Commit 32d7faf

Browse files
committed
Adding workflow files
1 parent 045d243 commit 32d7faf

3 files changed

Lines changed: 367 additions & 0 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Extraction of Citation File Format Metadata from MEI Files
2+
3+
on:
4+
push:
5+
branches:
6+
- ftr-39-add-actions-for-metadata-validation-and-extraction
7+
- develop
8+
pull_request:
9+
branches:
10+
- ftr-39-add-actions-for-metadata-validation-and-extraction
11+
- develop
12+
workflow_dispatch:
13+
14+
jobs:
15+
extract-citation-file-format:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout current Repository
20+
uses: actions/checkout@v6
21+
with:
22+
ref: develop
23+
24+
- name: Checkout Tools Repository
25+
uses: actions/checkout@v6
26+
with:
27+
repository: Edirom/mei-metadata-toolkit
28+
ref: main
29+
path: mei-metadata-toolkit
30+
31+
- name: Create necessary directories
32+
run: |
33+
mkdir -p .github/workflow-reports
34+
mkdir -p metadata/cff
35+
echo "OUTPUT_DIR=$(pwd)/metadata/cff" >> $GITHUB_ENV
36+
37+
- name: Install Java and Saxon-HE
38+
run: |
39+
REPORT="$REPORT_FILE"
40+
echo "Installing Java..."
41+
sudo apt-get update
42+
sudo apt-get install -y default-jre-headless
43+
44+
echo "Downloading Saxon-HE..."
45+
# Using the 12.9 version as requested
46+
wget -q https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE12-9/SaxonHE12-9J.zip
47+
unzip -q SaxonHE12-9J.zip
48+
49+
# Verify the jar exists
50+
if [ ! -f "saxon-he-12.9.jar" ]; then
51+
echo "Error: Saxon JAR not found after unzip."
52+
exit 1
53+
fi
54+
55+
echo "SAXON_JAR=$(pwd)/saxon-he-12.9.jar" >> $GITHUB_ENV
56+
echo "Java Version:"
57+
java -version
58+
59+
- name: Find all XML files and extract Citation File Format metadata
60+
env:
61+
REPORT_FILE: ".github/workflow-reports/mei-citation-file-format-extraction.md"
62+
run: |
63+
REPORT="$REPORT_FILE"
64+
65+
find . -type f -name "*.xml" \
66+
! -path "./.github/*" \
67+
! -path "./vendor/*" \
68+
! -path "./.git/*" \
69+
! -name "*.xml.bak" \
70+
> xml_files.txt
71+
72+
# write date and time to report
73+
echo "Citation File Format metadata extraction started at $(date)" >> "$REPORT"
74+
echo "Found $(wc -l < xml_files.txt) XML files to process." >> "$REPORT"
75+
76+
# prepare file list for XSLT processing
77+
input_files=""
78+
while IFS= read -r file; do
79+
input_files="$input_files $file"
80+
done < xml_files.txt
81+
echo "INPUT_FILES=$input_files" >> $GITHUB_ENV
82+
83+
# run XSLT transformation to extract CFF metadata and provide input files as parameter
84+
java -jar "$SAXON_JAR" -o:"$OUTPUT_DIR/CITATION.cff" -s:"$input_files" -xsl:"$(pwd)/mei-metadata-toolkit/src/xsl/mei2cff.xsl" -param input-files "'$input_files'"
85+
86+
output_file="$OUTPUT_DIR/CITATION.cff"
87+
88+
if [ -f "$output_file" ]; then
89+
echo "Citation File Format metadata extracted successfully to $output_file" >> "$REPORT"
90+
else
91+
echo "Failed to create output file for $file" >> "$REPORT"
92+
fi
93+
94+
echo "" >> "$REPORT"
95+
96+
cat "$REPORT"
97+
98+
99+
- name: Upload Validation Report as Artifact
100+
if: always()
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: citation-file-format-extraction-report
104+
path: .github/workflow-reports/mei-citation-file-format-extraction.md
105+
106+
107+
- name: Commit and Push
108+
run: |
109+
git config --local user.email "action@github.com"
110+
git config --local user.name "GitHub Action"
111+
git add .github/workflow-reports/mei-citation-file-format-extraction.md
112+
git add metadata/cff/CITATION.cff
113+
git commit -m "Update Citation File Format extraction report" || echo "No changes to commit"
114+
git push
115+
# Note: The 'git push' step will fail in Pull Request workflows unless you use a specific token
116+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Extraction of Dublin Core Metadata from MEI Files
2+
3+
on:
4+
push:
5+
branches:
6+
- ftr-39-add-actions-for-metadata-validation-and-extraction
7+
- develop
8+
pull_request:
9+
branches:
10+
- ftr-39-add-actions-for-metadata-validation-and-extraction
11+
- develop
12+
workflow_dispatch:
13+
14+
jobs:
15+
extract-dublin-core:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout current Repository
20+
uses: actions/checkout@v6
21+
with:
22+
ref: develop
23+
24+
- name: Checkout Tools Repository
25+
uses: actions/checkout@v6
26+
with:
27+
repository: Edirom/mei-metadata-toolkit
28+
ref: main
29+
path: mei-metadata-toolkit
30+
31+
- name: Create necessary directories
32+
run: |
33+
mkdir -p .github/workflow-reports
34+
mkdir -p metadata/dc
35+
echo "OUTPUT_DIR=$(pwd)/metadata/dc" >> $GITHUB_ENV
36+
- name: Install Java and Saxon-HE
37+
run: |
38+
REPORT="$REPORT_FILE"
39+
echo "Installing Java..."
40+
sudo apt-get update
41+
sudo apt-get install -y default-jre-headless
42+
43+
echo "Downloading Saxon-HE..."
44+
# Using the 12.9 version as requested
45+
wget -q https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE12-9/SaxonHE12-9J.zip
46+
unzip -q SaxonHE12-9J.zip
47+
48+
# Verify the jar exists
49+
if [ ! -f "saxon-he-12.9.jar" ]; then
50+
echo "Error: Saxon JAR not found after unzip."
51+
exit 1
52+
fi
53+
54+
echo "SAXON_JAR=$(pwd)/saxon-he-12.9.jar" >> $GITHUB_ENV
55+
echo "Java Version:"
56+
java -version
57+
58+
- name: Find all XML files and extract Dublin Core metadata
59+
env:
60+
REPORT_FILE: ".github/workflow-reports/mei-dublin-core-extraction.md"
61+
run: |
62+
REPORT="$REPORT_FILE"
63+
# Initialize the report
64+
echo "### Dublin Core Extraction Report" > "$REPORT"
65+
echo "" >> "$REPORT"
66+
echo "Branch: ${{ github.ref_name }}" >> "$REPORT"
67+
echo "Generated: $(date)" >> "$REPORT"
68+
echo "" >> "$REPORT"
69+
echo "Found $(wc -l < xml_files.txt) XML files to process." >> "$REPORT"
70+
echo "" >> "$REPORT"
71+
find . -type f -name "*.xml" \
72+
! -path "./.github/*" \
73+
! -path "./vendor/*" \
74+
! -path "./.git/*" \
75+
! -name "*.xml.bak" \
76+
> xml_files.txt
77+
while IFS= read -r file; do
78+
java -jar "$SAXON_JAR" -o:"$OUTPUT_DIR/$(basename "$file" .xml)-dc.xml" -s:"$file" -xsl:"$(pwd)/mei-metadata-toolkit/src/xsl/mei2dc.xsl"
79+
output_file="$OUTPUT_DIR/$(basename "$file" .xml)-dc.xml"
80+
if [ -f "$output_file" ]; then
81+
if grep -q "<oai_dc:dc" "$output_file"; then
82+
echo "Dublin Core metadata extracted successfully to $output_file" >> "$REPORT"
83+
else
84+
echo "No Dublin Core metadata found in $file." >> "$REPORT"
85+
rm "$output_file"
86+
fi
87+
else
88+
echo "Failed to create output file for $file" >> "$REPORT"
89+
fi
90+
echo "" >> "$REPORT"
91+
92+
done < xml_files.txt
93+
echo "Dublin Core extraction completed. Extracted metadata files are located in $OUTPUT_DIR." >> "$REPORT"
94+
cat "$REPORT"
95+
96+
- name: Upload Validation Report as Artifact
97+
if: always()
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: dublin-core-extraction-report
101+
path: .github/workflow-reports/mei-dublin-core-extraction.md
102+
103+
- name: Commit and Push
104+
run: |
105+
git config --local user.email "action@github.com"
106+
git config --local user.name "GitHub Action"
107+
git add .github/workflow-reports/mei-dublin-core-extraction.md
108+
git add metadata/dc/*.xml
109+
git commit -m "Update Dublin Core extraction report" || echo "No changes to commit"
110+
git push
111+
# Note: The 'git push' step will fail in Pull Request workflows unless you use a specific token
112+
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Validation of Dublin Core compliance for MEI Files
2+
3+
on:
4+
push:
5+
branches:
6+
- ftr-39-add-actions-for-metadata-validation-and-extraction
7+
- develop
8+
pull_request:
9+
branches:
10+
- ftr-39-add-actions-for-metadata-validation-and-extraction
11+
- develop
12+
workflow_dispatch:
13+
14+
jobs:
15+
validate-schematron:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout current Repository
20+
uses: actions/checkout@v6
21+
with:
22+
ref: develop
23+
24+
- name: Checkout Tools Repository
25+
uses: actions/checkout@v6
26+
with:
27+
repository: Edirom/mei-metadata-toolkit
28+
ref: main
29+
path: mei-metadata-toolkit
30+
31+
- name: Create necessary directories
32+
run: |
33+
mkdir -p .github/workflow-reports
34+
35+
- name: Install Java and Saxon-HE
36+
run: |
37+
echo "Installing Java..."
38+
sudo apt-get update
39+
sudo apt-get install -y default-jre-headless
40+
41+
echo "Downloading Saxon-HE..."
42+
# Using the 12.9 version as requested
43+
wget -q https://github.com/Saxonica/Saxon-HE/releases/download/SaxonHE12-9/SaxonHE12-9J.zip
44+
unzip -q SaxonHE12-9J.zip
45+
46+
# Verify the jar exists
47+
if [ ! -f "saxon-he-12.9.jar" ]; then
48+
echo "Error: Saxon JAR not found after unzip."
49+
exit 1
50+
fi
51+
52+
echo "SAXON_JAR=$(pwd)/saxon-he-12.9.jar" >> $GITHUB_ENV
53+
echo "Java Version:"
54+
java -version
55+
56+
- name: Find all XML files and validate against Schematron
57+
id: validation
58+
env:
59+
SCHEMATRON_FILE: "mei-metadata-toolkit/src/schema/mei-dc.sch"
60+
REPORT_FILE: ".github/workflow-reports/mei-dublin-core-validation.md"
61+
run: |
62+
63+
find . -type f -name "*.xml" \
64+
! -path "./.github/*" \
65+
! -path "./vendor/*" \
66+
! -path "./.git/*" \
67+
! -name "*.xml.bak" \
68+
> xml_files.txt
69+
70+
REPORT="$REPORT_FILE"
71+
72+
# Initialize the report
73+
echo "### Schematron Validation Report" > "$REPORT"
74+
echo "Generated: $(date)" >> "$REPORT"
75+
echo "" >> "$REPORT"
76+
echo "Branch: ${{ github.ref_name }}" >> "$REPORT"
77+
echo "" >> "$REPORT"
78+
echo "Found $(wc -l < xml_files.txt) XML files to process." >> "$REPORT"
79+
echo "" >> "$REPORT"
80+
81+
# Read the file list
82+
while IFS= read -r file; do
83+
[ -z "$file" ] && continue
84+
85+
TOTAL_FILES=$((TOTAL_FILES + 1))
86+
echo "Processing file $TOTAL_FILES/$TOTAL_FILES: $file"
87+
88+
echo "Validating: $file" >> "$REPORT"
89+
90+
# Run Saxon-HE
91+
# -s: Source XML file
92+
# -schematron: The Schematron schema file
93+
# 2>&1: Capture both stdout and stderr
94+
95+
96+
# Verify the schematron file exists
97+
if [ ! -f "$SCHEMATRON_FILE" ]; then
98+
echo "Error: Schematron file not found."
99+
exit 1
100+
fi
101+
102+
103+
output=$(java -jar "$SAXON_JAR" -s="$file" -schematron="$SCHEMATRON_FILE" 2>&1)
104+
exit_code=$?
105+
set -e
106+
107+
if [ $exit_code -eq 0 ]; then
108+
echo " ✅ Status: PASSED" >> "$REPORT"
109+
echo "" >> "$REPORT"
110+
PASSED_FILES=$((PASSED_FILES + 1))
111+
else
112+
ALL_SUCCESS=false
113+
echo " ❌ Status: FAILED" >> "$REPORT"
114+
echo " --- Error Messages ---" >> "$REPORT"
115+
# Print the error output
116+
echo "$output" >> "$REPORT"
117+
echo "" >> "$REPORT"
118+
FAILED_FILES=$((FAILED_FILES + 1))
119+
fi
120+
done < xml_files.txt
121+
122+
cat "$REPORT"
123+
124+
- name: Upload Validation Report as Artifact
125+
if: always()
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: mei-dc-validation-report
129+
path: .github/workflow-reports/mei-dc-validation_report.md
130+
131+
- name: Commit and Push
132+
run: |
133+
git config --local user.email "action@github.com"
134+
git config --local user.name "GitHub Action"
135+
git add .github/workflow-reports/mei-dc-validation_report.md
136+
git commit -m "Update Dublin Core validation report" || echo "No changes to commit"
137+
git push
138+
# Note: The 'git push' step will fail in Pull Request workflows unless you use a specific token
139+

0 commit comments

Comments
 (0)