Kamakura, Kanagawa, Japan #103
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: Process Image on Commit | |
on: | |
push: | |
paths: | |
- "photos/**" # Trigger on changes within the 'photos' directory | |
permissions: | |
contents: write # Allow write access to the repository contents | |
jobs: | |
process_image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref }} # Checkout the specific branch or tag that triggered the workflow | |
fetch-depth: 0 # Fetch all history so we can access previous commits | |
persist-credentials: true # Ensure credentials are persisted for pushing changes | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: | | |
npm install sharp exiftool-vendored fs-extra xml2js | |
- name: Process Images | |
run: | | |
for file in $(git diff --name-only --diff-filter=A HEAD^ HEAD | grep -E '^photos/.*\.(jpg|jpeg|png)$'); do | |
node process_image.js "$file" | |
done | |
- name: List changed files | |
run: git status | |
- name: Commit changes | |
run: | | |
shopt -s nullglob | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "actions@github.com" | |
# Get the original commit message without '[skip ci]' | |
LAST_COMMIT_MESSAGE=$(git log -1 --pretty=%B | sed 's/\[skip ci\]//g' | sed 's/[[:space:]]*$//') | |
# Add '[skip ci]' to prevent retriggering | |
COMMIT_MESSAGE="$LAST_COMMIT_MESSAGE [skip ci]" | |
git add --all | |
git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit" | |
- name: Push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git push origin HEAD:${{ github.ref_name }} || echo "Nothing to push" |