Merge pull request #1427 from City-of-Helsinki/hds-2522-announcement-… #161
Workflow file for this run
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
# Build icon library, create zip file for release and commit to current branch | |
name: update icon library | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- release-* | |
jobs: | |
build-icon-library: | |
runs-on: ubuntu-latest | |
env: | |
FILE_KEY: 'Kxwg3R0zNRHj55nQqFu6VS' | |
NODE_ID: '172:2478' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.3.1' | |
registry-url: 'https://registry.npmjs.org' | |
# Don't do anything if we're on development, main or master branches | |
- name: Check branch | |
run: | | |
if [[ $GITHUB_REF == refs/heads/development || $GITHUB_REF == refs/heads/master || $GITHUB_REF == refs/heads/main ]]; then | |
echo "Development, master pr main branch, skipping icon library build" | |
exit 1 | |
fi | |
# Don't do anything if we're on release-x.x.x AND the icon-kit has the same version number (already built for the release) | |
# Skip this step if workflow was triggered by workflow_dispatch | |
- name: Check if icon library has already been built for this release | |
id: build_checker | |
if: github.event_name != 'workflow_dispatch' | |
run: | | |
PKG_VER=`node -pe "require('./packages/react/package.json').version"` | |
ICON_KIT_VER=`sed -n -E 's/.*version[[:space:]]+([0-9]+([.][0-9]+)*).*/\1/p' ./release/icon-kit-template-CHANGELOG.txt` | |
if [[ ${PKG_VER} == ${ICON_KIT_VER} ]]; then | |
echo "Icon library has already been built for this release, skipping" | |
echo "SKIP_REST_STEPS=true" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
- name: Run Glypfig | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
npx glypfig \ | |
--apikey $API_KEY \ | |
--filekey $FILE_KEY \ | |
--nodeid $NODE_ID \ | |
--format png,svg,css,react \ | |
--optimize \ | |
--template tsx \ | |
--csspath './release/icon-kit-template-css.eta' \ | |
--jspath './release/icon-kit-template-react-tsx.eta' \ | |
--cssprefix '' \ | |
--license './release/LICENSE.txt' \ | |
--pngscale 2.66 \ | |
--filter 'Size=S' | |
env: | |
API_KEY: ${{ secrets.HDS_ICON_KIT }} | |
- name: Append React interface into index file | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
echo -e "export { IconProps, IconSize } from './Icon.interface';\n" | \ | |
cat - ./icon-library/react/tsx/index.ts > temp && mv temp ./icon-library/react/tsx/index.ts | |
- name: Bump version in Changelog | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
PKG_VER=`node -pe "require('./packages/react/package.json').version"` | |
sed -i -E "s/version [0-9]{1,2}.[0-9]{1,2}.[0-9]{1,2}/version ${PKG_VER}/" ./release/icon-kit-template-CHANGELOG.txt | |
- name: Copy Changelog file to icon library | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: cp ./release/icon-kit-template-CHANGELOG.txt ./icon-library/CHANGELOG.txt | |
- name: Create release zip file | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
uses: TheDoctor0/zip-release@0.7.6 | |
with: | |
filename: 'release/hds-icon-kit.zip' | |
path: './icon-library' | |
- name: Copy svg files to repo folders | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: cp ./icon-library/svg/* ./packages/core/src/svg | |
- name: Copy css files to repo folders | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: cp ./icon-library/css/* ./packages/core/src/icons | |
- name: Copy react files to repo folders | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: cp ./icon-library/react/tsx/* ./packages/react/src/icons | |
- name: Install React package NPM dependencies | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: (cd ./packages/react && yarn) | |
- name: Lint React files | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: npx prettier --write './packages/react/src/icons/*.{ts,tsx}' | |
- name: Code analysis for React files | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: npx eslint --debug -c './packages/react/.eslintrc.json' --ignore-path './packages/react/.eslintignore' --fix './packages/react/src/icons/*.{ts,tsx}' | |
- name: Remove icon library build directory | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: rm -rf ./icon-library | |
# Update docsite icon list | |
- name: Run curl to get data from figma | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
curl -H "X-FIGMA-TOKEN: ${API_KEY}" "https://api.figma.com/v1/files/${FILE_KEY}/nodes?ids=${NODE_ID}&depth=2" | \ | |
jq --arg nodeid $NODE_ID '.nodes[$nodeid].document.children | .[] | {group: .name?, icon: .children[]?.name?}' | \ | |
jq -s .> icon_group.json | |
env: | |
API_KEY: ${{ secrets.HDS_ICON_KIT }} | |
working-directory: ./site | |
- name: regenerate iconlist | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
yarn iconlist | |
working-directory: ./site | |
- name: Commit changed files | |
if: steps.build_checker.outputs.SKIP_REST_STEPS != 'true' | |
run: | | |
git config --global user.email "hds@hel.fi" | |
git config --global user.name "Github Actions" | |
git add . | |
git commit -m 'Updated icon library' | |
git push | |
- name: End | |
run: echo "Done!" |