From 7ac3ab502c9d530a265c186ab34c42e0c69c8c1c Mon Sep 17 00:00:00 2001 From: Jan Slifka Date: Wed, 22 Jan 2025 13:40:32 +0100 Subject: [PATCH] Add guide links workflow --- .github/workflows/guide-links.yml | 52 +++++++++++++++++++++++++++++++ .gitignore | 3 ++ package.json | 11 ++++--- scripts/create-guide-links.js | 14 +++++++++ 4 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/guide-links.yml create mode 100644 scripts/create-guide-links.js diff --git a/.github/workflows/guide-links.yml b/.github/workflows/guide-links.yml new file mode 100644 index 000000000..2a157a783 --- /dev/null +++ b/.github/workflows/guide-links.yml @@ -0,0 +1,52 @@ +name: Guide Links CI + +on: + push: + tags: + - v* + +jobs: + pot: + name: Create guide links + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [ 20 ] + + steps: + - name: '[setup] Checkout Project' + uses: actions/checkout@v4 + + - name: '[setup] Node.js ${{ matrix.node-version }}' + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: '[app] Install' + run: | + npm ci + + - name: '[app] Create Guide Links' + run: | + npm run guide-links + + - name: '[release] Check Prerelease' + id: check_prerelease + run: | + GITHUB_TAG=`echo $GITHUB_REF | cut -d/ -f3` + if [[ $GITHUB_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "is_prerelease=false" >> "$GITHUB_OUTPUT" + else + echo "is_prerelease=true" >> "$GITHUB_OUTPUT" + fi + + - name: '[release] Create & Upload Artifacts' + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + artifactErrorsFailBuild: true + artifacts: "guide-links.json" + artifactContentType: application/json + prerelease: ${{ steps.check_prerelease.outputs.is_prerelease }} + replacesArtifacts: true diff --git a/.gitignore b/.gitignore index 412d2d8ed..b9c24dbae 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ engine-wizard/static/wizard/config.js # locale !*/locale /locale + +# guide links +guide-links.json diff --git a/package.json b/package.json index be04f1682..1e7a7d92f 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,11 @@ "build:registry": "COMPONENT=registry ./scripts/build.sh", "build:wizard": "COMPONENT=wizard ./scripts/build.sh", "clean": "rm -rf dist", + "guide-links": "node scripts/create-guide-links.js", + "pot": "mkdir -p locale && npm run pot:registry && npm run pot:wizard", + "pot:registry": "COMPONENT=registry node scripts/create-pot-file.js", + "pot:wizard": "COMPONENT=wizard node scripts/create-pot-file.js", + "review": "elm-review", "start": "npm run start:wizard", "start:registry": "COMPONENT=registry webpack serve", "start:wizard": "COMPONENT=wizard webpack serve", @@ -16,11 +21,7 @@ "test:registry": "npm run test:elm", "test:wizard": "npm run test:elm && npm run test:wizard:icon-set && npm run test:wizard:locale", "test:wizard:icon-set": "COMPONENT=wizard node scripts/test-icon-set.js", - "test:wizard:locale": "COMPONENT=wizard node scripts/test-locale.js", - "review": "elm-review", - "pot": "mkdir -p locale && npm run pot:registry && npm run pot:wizard", - "pot:registry": "COMPONENT=registry node scripts/create-pot-file.js", - "pot:wizard": "COMPONENT=wizard node scripts/create-pot-file.js" + "test:wizard:locale": "COMPONENT=wizard node scripts/test-locale.js" }, "devDependencies": { "@lydell/elm": "^0.19.1-14", diff --git a/scripts/create-guide-links.js b/scripts/create-guide-links.js new file mode 100644 index 000000000..0a8c54ae8 --- /dev/null +++ b/scripts/create-guide-links.js @@ -0,0 +1,14 @@ +const fs = require('fs') + + +const elmFile = 'engine-wizard/elm/Wizard/Common/GuideLinks.elm' +const fileContent = fs.readFileSync(elmFile, 'utf8') +const keyValueRegex = /\( "(.*?)", "(.*?)" \)/g +const result = {} + +let line +while ((line = keyValueRegex.exec(fileContent)) !== null) { + result[line[1]] = line[2] +} + +fs.writeFileSync('guide-links.json', JSON.stringify(result, null, 2))