Skip to content

Fetch Icons

Fetch Icons #50

Workflow file for this run

###
#
# Regularly create a pull request with up-to-date icons
#
# This workflow has access to secrets and
# therefore will not run from a fork.
#
###
name: Fetch Icons
on:
workflow_dispatch:
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
- cron: '0 0 * * 0' # the job will run every Sunday at 0:00
jobs:
fetch:
runs-on: ubuntu-latest
if: github.repository_owner == 'swisspost'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup
uses: swisspost/design-system/.github/actions/setup-pnpm@main
- name: Get Date
id: current-date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Create Branch
id: current-branch
run: |
git checkout -b $BRANCH_NAME
echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT
env:
BRANCH_NAME: ${{ steps.current-date.outputs.date }}-update-icons
- name: Install icons & dependencies
run: pnpm --filter design-system-icons... --filter design-system-styles... install
- name: Fetch Icons
run: pnpm --filter design-system-icons fetchSVGs
env:
CEN_USERNAME: ${{ secrets.CEN_USERNAME }}
CEN_PASSWORD: ${{ secrets.CEN_PASSWORD }}
CEN_URL: ${{ secrets.CEN_URL }}
- name: Build styles
run: pnpm styles:build
- name: Commit Changes
run: |
git config --global user.name "swisspost-bot"
git config --global user.email "[email protected]"
git add .
git commit -am "chore(icons): update icon SVGs"
git push -u origin ${{ steps.current-branch.outputs.branch }}
- name: Get Changes
id: changed-files
uses: tj-actions/changed-files@v37
with:
files: ./packages/icons/public/post-icons/**
- name: Exit if no changes
if: steps.changed-files.outputs.any_modified == 'false'
run: |
git checkout main
git push origin --delete ${{ steps.current-branch.outputs.branch }}
- name: Get Changed Icons
id: changed-icons
if: steps.changed-files.outputs.any_modified != 'false'
run: |
get_icons() {
# takes the list of icon file paths
# replaces paths to keep the icon numbers only
# separates with commas and replace the last one with "and"
echo $@ | sed 's/[^ ]*\/\([[:digit:]]*\)\.svg/\1/g' | sed 's/ /, /g' | sed 's/\(.*\),/\1 and/g'
}
echo "added_icons=$(get_icons $ADDES_FILES)" >> $GITHUB_OUTPUT
echo "updated_icons=$(get_icons $MODIFIED_FILES $RENAMED_FILES $COPIED_FILES)" >> $GITHUB_OUTPUT
echo "deleted_icons=$(get_icons $DELETED_FILES)" >> $GITHUB_OUTPUT
env:
ADDES_FILES: ${{ steps.changed-files.outputs.added_files }}
MODIFIED_FILES: ${{ steps.changed-files.outputs.modified_files }}
RENAMED_FILES: ${{ steps.changed-files.outputs.renamed_files }}
COPIED_FILES: ${{ steps.changed-files.outputs.copied_files }}
DELETED_FILES: ${{ steps.changed-files.outputs.deleted_files }}
- name: Create Changeset
if: steps.changed-files.outputs.any_modified != 'false'
run: |
declare -a description
if [[ -n $ADDED_ICONS ]]; then
description+="Added icons number ${ADDED_ICONS}."
fi
if [[ -n $UPDATED_ICONS ]]; then
description+="Updated icons number ${UPDATED_ICONS}."
fi
if [[ -n $DELETED_ICONS ]]; then
description+="Deleted icons number ${DELETED_ICONS}."
fi
echo --- > $CHANGESET
echo "'@swisspost/design-system-icons': patch" >> $CHANGESET
echo --- >> $CHANGESET
echo >> $CHANGESET
echo "${description[@]}" >> $CHANGESET
echo >> $CHANGESET
env:
CHANGESET: ./.changeset/${{ steps.current-branch.outputs.branch }}.md
ADDED_ICONS: ${{ steps.changed-icons.outputs.added_icons }}
UPDATED_ICONS: ${{ steps.changed-icons.outputs.updated_icons }}
DELETED_ICONS: ${{ steps.changed-icons.outputs.deleted_icons }}
- name: Commit Changeset
if: steps.changed-files.outputs.any_modified != 'false'
run: |
git add .
git commit -am "chore(icons): add changeset"
git push -u origin ${{ steps.current-branch.outputs.branch }}
- name: Write PR Body
id: pr-body
if: steps.changed-files.outputs.any_modified != 'false'
run: |
echo "file=$PR_BODY_FILE" >> $GITHUB_OUTPUT
echo "# Design system icons are now up to date!" > $PR_BODY_FILE
if [[ -n $ADDED_ICONS ]]; then
echo "## Added icons" >> $PR_BODY_FILE
echo $ADDED_ICONS >> $PR_BODY_FILE
fi
if [[ -n $UPDATED_ICONS ]]; then
echo "## Updated icons" >> $PR_BODY_FILE
echo $UPDATED_ICONS >> $PR_BODY_FILE
fi
if [[ -n $DELETED_ICONS ]]; then
echo "## Deleted icons" >> $PR_BODY_FILE
echo $DELETED_ICONS >> $PR_BODY_FILE
fi
env:
PR_BODY_FILE: pr-body.md
ADDED_ICONS: ${{ steps.changed-icons.outputs.added_icons }}
UPDATED_ICONS: ${{ steps.changed-icons.outputs.updated_icons }}
DELETED_ICONS: ${{ steps.changed-icons.outputs.deleted_icons }}
- name: Create PR
if: steps.changed-files.outputs.any_modified != 'false'
run: |
gh pr create --title "chore(icons): :point_up: update icons" --body-file ${{ steps.pr-body.outputs.file }}
env:
GITHUB_TOKEN: ${{ secrets.ICON_WORKFLOW_PAT }}