Skip to content

Generate exports & Publish NPM package #131

Generate exports & Publish NPM package

Generate exports & Publish NPM package #131

Workflow file for this run

name: Generate exports & Publish NPM package
on:
push:
workflow_dispatch:
workflow_run:
workflows: ["Keep Google Material Icons up-to-date"]
types: [completed]
jobs:
apply-updates:
if: github.ref == 'refs/heads/main'
name: Push changes & publish NPM package
runs-on: ubuntu-latest
steps:
- name: Check out this repo
uses: actions/checkout@v2
- uses: actions/github-script@v4
name: Get version from package.json
id: package-json
with:
script: |-
const fs = require('fs');
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
core.setOutput('version', packageJson.version);
- uses: actions/github-script@v4
name: Generate re-exports
with:
script: |-
const path = require('path');
const fs = require('fs');
const ICONS_ROOT = './icons';
let indexJsContent = '';
const exportsContents = {
animated: '',
baseline: '',
outline: '',
round: '',
sharp: '',
twotone: '',
};
const globber = await glob.create(
`${ICONS_ROOT}/**/*.svg`,
{ implicitDescendants: false },
);
for await (const file of globber.globGenerator()) {
const relativePath = path.relative(ICONS_ROOT, file)
const exportName = relativePath
.replace(/[\/_-]./g, group => group[1].toUpperCase())
.slice(0, -4);
let [,, iconVariation] = relativePath.split('/');
iconVariation = iconVariation.replace(/_thin|.svg/g, '');
exportsContents[iconVariation] += `export { default as ${exportName} } from '${ICONS_ROOT}/${relativePath}';\n`;
}
for (const [variation, contents] of Object.entries(exportsContents)) {
indexJsContent += `export * from './${variation}.js';\n`;
fs.writeFileSync(`./${variation}.js`, contents);
}
fs.writeFileSync('./index.js', indexJsContent);
- name: Commit and push if changed
run: |-
git config user.name "GitHub Actions"
git config user.email "actions@users.noreply.github.com"
git add *.js package.json
git commit -m "Generate exports for v${{ steps.package-json.outputs.version }}" || true
git push --force origin main
git tag "${{ steps.package-json.outputs.version }}"
git push --force origin "${{ steps.package-json.outputs.version }}"
- name: Publish NPM package
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
access: "public"
dry-run: false
check-version: true