Modify Icons #15
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: Modify Icons | |
on: | |
workflow_run: | |
workflows: ["Sync Upstream Icons"] | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
process: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout Fork Repo | |
- name: Checkout Fork Repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Step 2: Set up Node.js environment | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
# Step 3: Install oslllo-svg-fixer | |
- name: Install oslllo-svg-fixer | |
run: npm install -g oslllo-svg-fixer | |
# Step 4: Create necessary folders | |
- name: Create Necessary Folders | |
run: | | |
mkdir -p icons/combined temp-icons | |
# Step 5: Move and Rename Icons | |
- name: Move and Rename Filled Icons | |
run: | | |
for file in icons/filled/*.svg; do | |
mv "$file" "icons/combined/$(basename "${file%.svg}")-filled.svg" | |
done | |
- name: Move and Rename Outline Icons | |
run: | | |
for file in icons/outline/*.svg; do | |
mv "$file" "temp-icons/$(basename "${file%.svg}")-outline.svg" | |
done | |
# Step 6: Run oslllo-svg-fixer | |
- name: Run oslllo-svg-fixer | |
run: oslllo-svg-fixer --source temp-icons --destination icons/combined | |
# Step 7: Commit and Push Changes | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
git add icons/combined/ | |
git status | |
if git commit -m "Processed and updated SVG icons in combined folder"; then | |
echo "Committed changes." | |
git push | |
else | |
echo "No changes to commit or commit failed." | |
exit 1 | |
fi | |
# Step 8: Zip the Icons | |
- name: Zip Icons | |
run: zip -r kustom-tabler-icons.zip icons/combined | |
# Step 9: Fetch Latest Tag from Upstream and Set Output | |
- name: Fetch Latest Tag from Upstream | |
id: fetch_tag | |
run: | | |
LATEST_TAG=$(git ls-remote --tags https://github.com/tabler/tabler-icons.git | \ | |
grep -o 'refs/tags/.*' | sed 's/refs\/tags\///' | sort -V | tail -n1) | |
echo "::set-output name=LATEST_TAG::$LATEST_TAG" | |
outputs: | |
LATEST_TAG: ${{ steps.fetch_tag.outputs.LATEST_TAG }} | |
# Step 10: Create or Update GitHub Release | |
release: | |
runs-on: ubuntu-latest | |
needs: process | |
steps: | |
- name: Create or Update GitHub Release | |
id: create_or_update_release | |
run: | | |
TAG_NAME="${{ needs.process.outputs.LATEST_TAG }}" | |
RELEASE_NAME="Kustom Tabler Icons - $TAG_NAME" | |
API_URL="https://api.github.com/repos/${{ github.repository }}/releases" | |
# Check if release with tag already exists | |
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $API_URL | \ | |
jq -r ".[] | select(.tag_name == \"$TAG_NAME\") | .id") | |
if [ -z "$RELEASE_ID" ]; then | |
# Create a new release if it doesn't exist | |
RESPONSE=$(curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d '{"tag_name": "'"$TAG_NAME"'","name": "'"$RELEASE_NAME"'","draft": false,"prerelease": false}' \ | |
$API_URL) | |
UPLOAD_URL=$(echo "$RESPONSE" | jq -r ".upload_url" | sed 's/{?name,label}//') | |
echo "::set-output name=upload_url::$UPLOAD_URL" | |
else | |
# Update the existing release if it does | |
RESPONSE=$(curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d '{"name": "'"$RELEASE_NAME"'"}' \ | |
"$API_URL/$RELEASE_ID") | |
UPLOAD_URL=$(echo "$RESPONSE" | jq -r ".upload_url" | sed 's/{?name,label}//') | |
echo "::set-output name=upload_url::$UPLOAD_URL" | |
fi | |
outputs: | |
upload_url: ${{ steps.create_or_update_release.outputs.upload_url }} | |
# Step 11: Upload the zip file to the GitHub release | |
upload: | |
runs-on: ubuntu-latest | |
needs: release | |
steps: | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: ./kustom-tabler-icons.zip | |
asset_name: kustom-tabler-icons.zip | |
asset_content_type: application/zip |