Bump tj-actions/changed-files from 5.2 to 41 in /.github/workflows #107
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: Manage updated assets | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
MAX_SIZE: 2048 | |
PROCESS_ALL: 'false' | |
jobs: | |
process: | |
runs-on: ubuntu-latest | |
name: Process changed files | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit. | |
lfs: 'true' | |
- name: Get changed files | |
id: changed-files | |
with: | |
files: raw | |
separator: "," | |
uses: tj-actions/changed-files@v41 | |
- uses: mfinelli/setup-imagemagick@v1 | |
- name: Process all modified files | |
run: | | |
max_size=${{env.MAX_SIZE}} | |
modified_files_string="${{ steps.changed-files.outputs.all_modified_files }}"; | |
if [ ${{env.PROCESS_ALL}} = "true" ] | |
then | |
echo "Processing all files" | |
files_array=$(find raw -type f) | |
else | |
echo "Processing only changed files" | |
files_array=$(echo $modified_files_string | tr "," "\n") | |
fi | |
for file in $files_array | |
do | |
file_dir=$(dirname $file) | |
echo -e "- \e[97m$file\e[0m:" | |
# Ignore files in "extra" subfolder | |
if [[ $file_dir == raw/extra* ]]; then | |
echo -e " \e[3mIgnoring asset in 'extra' folder\e[0m" | |
else | |
# Get image size and show it | |
width=$(magick identify -ping -format '%w' $file[0]) | |
height=$(magick identify -ping -format '%w' $file[0]) | |
echo -e " $width x $height px" | |
# Retrieve and store some image metadata | |
keywords=$(magick identify -quiet -format %[IPTC:2:25] $file[0]) | |
copyright=$(magick identify -quiet -format %[EXIF:COPYRIGHT*] $file[0]) | |
author=$(magick identify -quiet -format %[IPTC:2:80] $file[0]) | |
# Warn about missing data | |
if [ -z "$author" ]; then | |
echo -e " \e[93mWarning: no author information found\e[0m" | |
else | |
echo -e " Author: \e[36m$author\e[0m" | |
fi | |
name=$(magick identify -quiet -format %[IPTC:2:5] $file[0]) | |
if [ -z "$name" ]; then | |
echo -e " \e[93mWarning: no name information found\e[0m" | |
else | |
echo -e " Name: \e[36m$author\e[0m" | |
fi | |
if [ -z "$copyright" ]; then | |
echo -e " \e[93mWarning: no copyright information found\e[0m" | |
else | |
echo -e " Image copyright information: \e[36m$copyright\e[0m" | |
fi | |
# Check if the image is a sprite ("sprite" keyword is detected) | |
if [[ $(echo "$keywords" | tr '[:lower:]' '[:upper:]' ) == *"SPRITE"* ]]; then | |
isSprite=true | |
else | |
isSprite=false | |
fi | |
# Set destination filename, folder and format | |
name_ext=$(basename $file) | |
name=$(echo "$name_ext" | cut -f 1 -d '.') | |
ext="${name_ext##*.}" | |
if [ "$isSprite" = true ] ; then | |
echo " Sprite keyword detected: destination format is PNG" | |
new_ext=".png" | |
else | |
echo " Sprite keyword not detected: destination format is JPEG" | |
new_ext=".jpg" | |
fi | |
output_file="${file_dir/raw/src/assets}/$name$new_ext" | |
# Actual image processing | |
mkdir -p ${file_dir/raw/src/assets} | |
if (( width > max_size || height > max_size )); then | |
echo " Must be processed as is bigger than $max_size" | |
echo " Converting to $output_file" | |
geometry="${max_size}x${max_size}" | |
magick convert $file[0] -resize $geometry $output_file | |
else | |
if [[ $(echo ".$ext" | tr '[:lower:]' '[:upper:]' ) != $(echo "$new_ext" | tr '[:lower:]' '[:upper:]' ) ]]; then | |
echo " Converting file format from $ext to $new_ext" | |
magick convert $file[0] $output_file | |
else | |
echo " Copying file to destination" | |
cp $file $output_file | |
fi | |
fi | |
fi | |
echo "" | |
done | |
- name: Archive generated images | |
uses: actions/upload-artifact@v2 | |
with: | |
name: assets | |
path: src/assets | |
- name: Update resources | |
uses: test-room-7/action-update-file@v1 | |
with: | |
file-path: | | |
src/assets/**/*.jpg | |
src/assets/**/*.png | |
commit-msg: Update processed assets | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Generate contact sheet | |
run: | | |
if [ -d "/tmp/contactsheet" ] | |
then | |
rm -rf /tmp/contactsheet | |
else | |
mkdir -p /tmp/contactsheet | |
fi | |
cp -n src/assets/**/* /tmp/contactsheet | |
montage -verbose -label '%[IPTC:2:5]' -define jpeg:size=240x240 -geometry 240x240+2+2 -font DejaVu-Sans /tmp/contactsheet/*[0] raw/extra/contact-sheet.png | |
- name: Generate HTML index | |
run: | | |
echo " | |
<html> | |
<head> | |
<title>Iakkai Saga Art Index</title> | |
</head> | |
<style> | |
* { box-sizing: border-box; } | |
.wrapper { | |
display:grid; | |
grid-template-columns: repeat(2, 1fr); | |
grid-gap:10px | |
} | |
.wrapper div div { | |
float:left; | |
margin-left:10px; | |
font-family: sans-serif; | |
font-size: 0.7em; | |
width: calc(59% - 10px) | |
} | |
.wrapper div img { | |
width: 40%; | |
max-width: 100%; | |
float: left; | |
} | |
</style> | |
<body> | |
<div class='wrapper'>" > raw/extra/art-index.html | |
for file in src/assets/**/*; do | |
echo "Processing $file" | |
echo " | |
<div> | |
<img src='../../$file'/> | |
<div> " >> raw/extra/art-index.html | |
echo "<span style='font-weight:bold'>$file</span><br/>" >> raw/extra/art-index.html | |
width=$(magick identify -ping -format '%w' $file[0]) | |
height=$(magick identify -ping -format '%w' $file[0]) | |
keywords=$(magick identify -quiet -format %[IPTC:2:25] $file[0]) | |
copyright=$(magick identify -quiet -format %[EXIF:COPYRIGHT*] $file[0]) | |
author=$(magick identify -quiet -format %[IPTC:2:80] $file[0]) | |
name=$(magick identify -quiet -format %[IPTC:2:5] $file[0]) | |
if [ -z "$name" ]; then | |
echo " Warning: no name information found<br/>" >> raw/extra/art-index.html; | |
else | |
echo " Name: $name<br/>" >> raw/extra/art-index.html; | |
fi | |
if [ -z "$author" ]; then | |
echo " Warning: no author information found<br/>" >> raw/extra/art-index.html; | |
else | |
echo " Author: $author<br/>" >> raw/extra/art-index.html; | |
fi | |
if [ -z "$copyright" ]; then | |
echo " Warning: no copyright information found<br/>" >> raw/extra/art-index.html; | |
else | |
echo " Copyright: $copyright<br/>" >> raw/extra/art-index.html; | |
fi | |
if [[ $(echo "$keywords" | tr '[:lower:]' '[:upper:]' ) == *"SPRITE"* ]]; then | |
echo " SPRITE keyword detected" >> raw/extra/art-index.html; | |
else | |
echo "" >> raw/extra/art-index.html; | |
fi | |
echo "</div></div>" >> raw/extra/art-index.html | |
done | |
echo "</div></html>" >> raw/extra/art-index.html | |
- name: Update contact sheet and HTML art index | |
uses: test-room-7/action-update-file@v1 | |
with: | |
file-path: | | |
raw/extra/art-index.html | |
raw/extra/contact-sheet.png | |
commit-msg: Update art index and contact sheet | |
github-token: ${{ secrets.GITHUB_TOKEN }} |