Update from upstream and convert SVG to PNG and WebP #39
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: Update from upstream and convert SVG to PNG and WebP | |
on: | |
schedule: | |
- cron: '0 0 * * *' # 毎日深夜に実行(必要に応じて変更) | |
workflow_dispatch: # 手動実行も可能 | |
jobs: | |
update-and-convert: | |
runs-on: ubuntu-latest | |
steps: | |
- name: リポジトリをチェックアウト | |
uses: actions/[email protected] | |
with: | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: upstreamを追加してフェッチ | |
run: | | |
git remote add upstream https://github.com/Richard9394/MingCute | |
git fetch upstream | |
git checkout main | |
git merge upstream/main --allow-unrelated-histories | |
- name: Inkscapeをインストール | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y inkscape | |
- name: SVGからPNGおよびWebPへの変換 | |
run: | | |
# SVGフォルダと同じ構造でpngフォルダとwebpフォルダを作成し、ファイルを変換・配置 | |
find svg -type f -name '*.svg' | while read svg_file; do | |
# 相対パスを取得(例:svg/arrow/icon.svg -> arrow/icon.svg) | |
relative_path="${svg_file#svg/}" | |
# 対応するPNGファイルのパスを作成 | |
png_file="png/${relative_path%.svg}.png" | |
mkdir -p "$(dirname "$png_file")" | |
# 対応するWebPファイルのパスを作成 | |
webp_file="webp/${relative_path%.svg}.webp" | |
mkdir -p "$(dirname "$webp_file")" | |
# PNG変換(背景を透明に設定) | |
if [ ! -f "$png_file" ] || [ "$svg_file" -nt "$png_file" ]; then | |
inkscape "$svg_file" --export-filename="$png_file" --export-background-opacity=0 | |
echo "Converted $svg_file to $png_file with transparent background" | |
fi | |
# WebP変換(PNGを経由してWebPに変換) | |
if [ ! -f "$webp_file" ] || [ "$svg_file" -nt "$webp_file" ]; then | |
# 一時的にPNGファイルを使用 | |
temp_png="/tmp/temp_image.png" | |
inkscape "$svg_file" --export-filename="$temp_png" --export-background-opacity=0 | |
# PNGからWebPに変換 | |
cwebp -q 100 "$temp_png" -o "$webp_file" | |
rm "$temp_png" | |
echo "Converted $svg_file to $webp_file with transparent background" | |
fi | |
done | |
- name: 変更をコミット | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
git add png | |
git add webp | |
if git diff --cached --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Update PNG and WebP files from SVG with transparent background" | |
fi | |
- name: 変更をプッシュ | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: main |