Skip to content

Updated de-at/de-de contracts #332

Updated de-at/de-de contracts

Updated de-at/de-de contracts #332

Workflow file for this run

name: Generate PDFs
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
preview:
timeout-minutes: 5
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "npm"
- run: npm ci
- run: npm run lint
- name: Get all changed markdown files
id: changed-contract-files
uses: tj-actions/changed-files@v45
with:
# Avoid using single or double quotes for multiline patterns
files: "**.md"
files_ignore: |
README.md
# Run the following steps only if any contract files have changed
- name: Generate preview files
if: steps.changed-contract-files.outputs.any_changed == 'true'
env:
CHANGED_FILES: ${{ steps.changed-contract-files.outputs.all_changed_files }}
run: |
current_date=$(date +"%d%m%Y")
for file in ${CHANGED_FILES}; do
filename=$(basename "$file")
base_filename="${filename%.md}"
new_filename=output/"${current_date}-${base_filename}-preview.pdf"
npm run generate "$file" "$new_filename" true
done
- uses: actions/upload-artifact@v4
if: steps.changed-contract-files.outputs.any_changed == 'true'
id: pdf-previews
with:
name: pdf-previews
path: ./output/*.pdf
- uses: peter-evans/find-comment@v3
if: steps.changed-contract-files.outputs.any_changed == 'true'
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- Contract Preview -->"
- uses: peter-evans/create-or-update-comment@v4
if: steps.changed-contract-files.outputs.any_changed == 'true'
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- Contract Preview -->
### Preview PDFs
You can download the generated PDFs from the artifacts: [pdf-previews](${{ steps.pdf-previews.outputs.artifact-url }}).
_Generated for commit ${{ github.event.pull_request.head.sha }}_
edit-mode: replace
commit:
needs: [preview]
timeout-minutes: 5
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Get all changed markdown files
id: changed-contract-files
uses: tj-actions/changed-files@v45
with:
# Avoid using single or double quotes for multiline patterns
files: "**.md"
files_ignore: |
README.md
# Run the following steps only if any contract files have changed
- uses: actions/setup-node@v4
if: steps.changed-contract-files.outputs.any_changed == 'true'
with:
node-version-file: ".nvmrc"
cache: "npm"
- run: npm ci
if: steps.changed-contract-files.outputs.any_changed == 'true'
- name: Generate real files
if: steps.changed-contract-files.outputs.any_changed == 'true'
env:
CHANGED_FILES: ${{ steps.changed-contract-files.outputs.all_changed_files }}
run: |
current_date=$(date +"%d%m%Y")
for file in ${CHANGED_FILES}; do
filename=$(basename "$file")
dirname=$(dirname "$file")
# Check if there are any existing PDFs in the directory before removing
if ls "$dirname"/*.pdf 1> /dev/null 2>&1; then
git rm "$dirname"/*.pdf
fi
# Generate new PDF
base_filename="${filename%.md}"
new_filename="${dirname}/${current_date}-${base_filename}.pdf"
npm run generate "$file" "$new_filename"
# Stage new changes
git add "$dirname"/*.pdf
done
# Commit and push changes
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch origin ${{ github.head_ref }}
git checkout ${{ github.head_ref }}
git commit -m "Generate PDFs for changed markdown files"
git push origin ${{ github.head_ref }}