started d1s3 #10
Workflow file for this run
This file contains 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
name: Run XML ID creation | |
on: | |
pull_request_target: | |
types: [ready_for_review] | |
jobs: | |
run-xslt: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
ref: ${{ github.event.pull_request.head.ref }} | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
- name: Set up Java | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '11' | |
- name: Download Saxon | |
run: | | |
wget https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/10.6/Saxon-HE-10.6.jar -O saxon.jar | |
- name: Download XSL file from Gist | |
run: | | |
wget https://gist.githubusercontent.com/jeffreycwitt/3c6c73b624000b6a94265d991aec8494/raw/08d0166c4f320200e18bc7d4d8a210e4ff7b1aa2/xmlid-creation.xslt -O stylesheet.xsl | |
- name: Download XSL Line Number Creation file from Gist | |
run: | | |
wget https://gist.githubusercontent.com/jeffreycwitt/07e9ca3cf73cad708f78bcf05273212f/raw/d93fe6ad36ebb31682eaa32d2dce14d950ee7605/line-number-creation.xsl -O stylesheetLineNumber.xsl | |
- name: Get changed files | |
id: changed-files | |
uses: actions/github-script@v4 | |
with: | |
script: | | |
const { data: files } = await github.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number, | |
}); | |
const changedFiles = files.map(file => file.filename).join(' '); | |
console.log("Changed files:", changedFiles); | |
core.setOutput('changedFiles', changedFiles); | |
- name: Set CHANGED_FILES environment variable | |
run: | | |
echo ${{ steps.changed-files.outputs.changedFiles }} | |
echo "CHANGED_FILES=${{ steps.changed-files.outputs.changedFiles }}" >> $GITHUB_ENV | |
- name: Set Target Branch | |
run: | | |
TARGET_BRANCH=${{ github.event.pull_request.head.ref }} | |
echo "TARGET_BRANCH=${TARGET_BRANCH}" >> $GITHUB_ENV | |
- name: Debug CHANGED_FILES | |
run: | | |
echo "Debugging CHANGED_FILES" | |
echo "$CHANGED_FILES" | |
- name: Run XSLT transformation | |
if: env.CHANGED_FILES != '' | |
run: | | |
echo "Changed files: $CHANGED_FILES" | |
for file in $CHANGED_FILES; do | |
echo $file | |
dir_name=$(dirname "$file") | |
echo $dir_name | |
base_file=$(basename "$file") | |
echo $base_file | |
if grep -q "<transcription use-for-extraction=\"true\">${base_file}</transcription>" ${dir_name}/transcriptions.xml; then | |
echo "Processing xml:id creation in canonical manifestation $file" | |
java -jar saxon.jar -s:$file -xsl:stylesheet.xsl -o:$file | |
else | |
echo "No matching transcription file found for $file" | |
fi | |
echo "Processing line number creation $file" | |
java -jar saxon.jar -s:$file -xsl:stylesheetLineNumber.xsl -o:$file | |
done | |
- name: Commit and push changes | |
if: env.CHANGED_FILES != '' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -x | |
git config --global user.name 'jeffreycwitt' | |
git config --global user.email 'jeffreycwitt@gmail.com' | |
git add $CHANGED_FILES | |
if git diff-index --quiet HEAD; then | |
echo "No changes to commit" | |
else | |
git commit -m 'Apply XSLT transformation to modified XML files' | |
git push origin HEAD:$TARGET_BRANCH | |
fi |