From 53eb8433455427632c527ccaebacadbc376ba260 Mon Sep 17 00:00:00 2001 From: william dutton Date: Wed, 27 Mar 2024 21:01:51 +1000 Subject: [PATCH] Add github actions workflows --- .github/workflows/README.md | 20 +++ .github/workflows/compile.js.yml | 143 ++++++++++++++++++ .github/workflows/storybook-deploy.js.yml | 55 +++++++ .github/workflows/updateChangeLog.yml | 37 +++++ package-lock.json | 25 +-- package.json | 3 +- src/components/bs5/banner/banner.stories.js | 10 +- .../bs5/blockquote/Blockquote.stories.js | 2 +- .../bs5/globalAlert/GlobalAlert.stories.js | 2 +- src/components/bs5/sidenav/data.json | 2 +- src/components/bs5/tag/Tag.stories.js | 2 +- 11 files changed, 279 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/README.md create mode 100644 .github/workflows/compile.js.yml create mode 100644 .github/workflows/storybook-deploy.js.yml create mode 100644 .github/workflows/updateChangeLog.yml diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 000000000..07f601c63 --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,20 @@ + +TARGET_REPO secret must be set + +e.g. + +qld-gov-au/formio-qld + +GH_TOKEN secret must be set + +At this time this for repo qld-gov-au/formio it is set to a GHA token for @duttonw + +structure of the GH_TOKEN is + +${username}:${token} + +e.g. username:mypersonalaccesstoken + +if this fails, generate a new token via +https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token +and update the secret \ No newline at end of file diff --git a/.github/workflows/compile.js.yml b/.github/workflows/compile.js.yml new file mode 100644 index 000000000..1ce5fda50 --- /dev/null +++ b/.github/workflows/compile.js.yml @@ -0,0 +1,143 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Build and Test + +on: + push: + pull_request: + +concurrency: + group: compile-${{ github.workflow }}-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession. + cancel-in-progress: true + +jobs: + validate: + + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '20'] + name: Lint test on Node ${{ matrix.node }} + steps: + - run: echo ${{github.ref}} + + - uses: actions/checkout@v4.1.2 + + - name: Use Node.js + uses: actions/setup-node@v4.0.2 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + #always-auth: 'true' + #registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' + + - name: npmrc #run on lint step (Which is cached) + run: | + npm -v + node -v + # cat /home/runner/work/_temp/.npmrc #only nice to test when registry is altered + #env: + #NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} + + - name: Install + run: | # Install packages + npm install --prefer-offline --no-audit --ignore-scripts + #env: + #NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} + + # `npm rebuild` will run all those post-install scripts for us. + - name: rebuild and prepare + run: npm rebuild && npm run prepare --if-present + + - name: Lint + run: | + npm run lint + - name: Test + run: | + npm run test + + build: + needs: validate + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '20' ] + name: Build and Deploy on Node ${{ matrix.node }} + steps: + - uses: actions/checkout@v4.1.2 + + - name: Use Node.js + uses: actions/setup-node@v4.0.2 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + #always-auth: 'true' + #registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' + - name: Install #run on lint step (Which is cached) + run: | # Install packages + npm install --prefer-offline --no-audit --ignore-scripts + #env: + #NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} + + # `npm rebuild` will run all those post-install scripts for us. + - name: rebuild and prepare + run: npm rebuild && npm run prepare --if-present + + - name: Build 🔧 + run: | # build the files + npm run build + - name: Build storybook 🔧 + run: | # build the Storybook files + npm run build-storybook + + - name: setup Package + run: | + ls -ltr + mkdir -p ./target/docs + cp -r ./storybook-static ./target/docs + cp -r ./dist/* ./target/. + + - uses: actions/upload-artifact@v4.3.1 + with: + name: Package + path: ./target + + + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + + - name: display branch name + shell: bash + run: echo "${{ steps.extract_branch.outputs.branch }}" + + - name: setup Publish + run: | + set -x + cp -r ./binary-repo/* ./dist + + - name: Publish qgds-qol-dist + uses: qld-gov-au/gha-publish-to-git@master + with: + repository: ${{ secrets.TARGET_REPO }} + git_ref: '${{ github.ref }}' + branch: '${{ steps.extract_branch.outputs.branch }}' + github_token: '${{ secrets.GH_TOKEN }}' + github_pat: '${{ secrets.GH_PAT }}' + source_folder: dist + tag_branch: main + if: success() + + - name: Publish to qgds-qol-cdn + uses: qld-gov-au/gha-cdn-version-tree-by-tag-builder@main + with: + repository: 'qld-gov-au/formio-qld-cdn' + git_ref: '${{ github.ref }}' + branch: 'release' + github_token: '${{ secrets.GH_TOKEN }}' + github_pat: '${{ secrets.GH_PAT }}' + source_folder: dist + if: success() + diff --git a/.github/workflows/storybook-deploy.js.yml b/.github/workflows/storybook-deploy.js.yml new file mode 100644 index 000000000..7f1cd26a1 --- /dev/null +++ b/.github/workflows/storybook-deploy.js.yml @@ -0,0 +1,55 @@ +name: Storybook deploy + +on: + workflow_run: + workflows: [Build and Test] # Reuse the name of your tests workflow + branches: [main, develop] + types: [completed ] + +concurrency: + group: deploy-${{ github.workflow }}-${{ github.ref }} # Recommended if you intend to make multiple deployments in quick succession. + cancel-in-progress: true + +jobs: + deploy: + + runs-on: ubuntu-latest + strategy: + matrix: + node: [ '16' ] + name: Deploy with Node ${{ matrix.node }} + if: ${{ github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4.1.2 + + - name: Use Node.js + uses: actions/setup-node@v4.0.2 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + #always-auth: 'true' + #registry-url: 'https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/' + - name: Install + run: | # Install packages + npm install --prefer-offline --no-audit --ignore-scripts + env: + #NODE_AUTH_TOKEN: ${{ secrets.NEXUSREADONLY2NPMTOKEN }} + + # `npm rebuild` will run all those post-install scripts for us. + - name: rebuild and prepare + run: npm rebuild && npm run prepare --if-present + + - name: Build 🔧 + run: | # build the Storybook files + npm run build + - name: Build Storybook 🔧 + run: | # build the Storybook files + npm run build-storybook + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@v4 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages # The branch the action should deploy to. + FOLDER: storybook-static # The folder that the build-storybook script generates files. + CLEAN: true # Automatically remove deleted files from the deploy branch + TARGET_FOLDER: docs # The folder that we serve our Storybook files from diff --git a/.github/workflows/updateChangeLog.yml b/.github/workflows/updateChangeLog.yml new file mode 100644 index 000000000..108f8e688 --- /dev/null +++ b/.github/workflows/updateChangeLog.yml @@ -0,0 +1,37 @@ +name: Update Changelog +on: + release: + types: [published] + workflow_dispatch: + inputs: + description: + description: 'Manual change log update' +jobs: + updateChangelog: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Update Changelog + # https://github.com/git-chglog/git-chglog#getting-started + run: | + mkdir tmp + pushd tmp + curl -o git-chglog.tar.gz -L https://github.com/git-chglog/git-chglog/releases/download/v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz + #curl -o git-chglog.tar.gz -L https://github.com/git-chglog/git-chglog/releases/download/v0.15.1/git-chglog_0.15.1_darwin_amd64.tar.gz + tar -zxvf git-chglog.tar.gz + cp ./git-chglog ../git-chglog + popd + rm -rf tmp + chmod u+x git-chglog + ./git-chglog -o CHANGELOG.md + rm git-chglog + - name: Create Pull Request + uses: peter-evans/create-pull-request@v4 + with: + commit-message: update changelog + title: Update Changelog + body: Update changelog to reflect release changes + branch: update-changelog + base: main diff --git a/package-lock.json b/package-lock.json index b796dc599..08e609d9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,7 +40,7 @@ "esbuild-plugin-copy": "^2.1.1", "esbuild-plugin-handlebars": "^1.0.2", "eslint": "^8.56.0", - "eslint-plugin-storybook": "^0.6.15", + "eslint-plugin-storybook": "^0.8.0", "onchange": "^7.1.0", "postcss": "^8.4.29", "prettier": "^2.8.8", @@ -11667,18 +11667,19 @@ } }, "node_modules/eslint-plugin-storybook": { - "version": "0.6.15", - "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.15.tgz", - "integrity": "sha512-lAGqVAJGob47Griu29KXYowI4G7KwMoJDOkEip8ujikuDLxU+oWJ1l0WL6F2oDO4QiyUFXvtDkEkISMOPzo+7w==", + "version": "0.8.0", + "resolved": "https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/eslint-plugin-storybook/-/eslint-plugin-storybook-0.8.0.tgz", + "integrity": "sha512-CZeVO5EzmPY7qghO2t64oaFM+8FTaD4uzOEjHKp516exyTKo+skKAL9GI3QALS2BXhyALJjNtwbmr1XinGE8bA==", "dev": true, + "license": "MIT", "dependencies": { "@storybook/csf": "^0.0.1", - "@typescript-eslint/utils": "^5.45.0", - "requireindex": "^1.1.0", + "@typescript-eslint/utils": "^5.62.0", + "requireindex": "^1.2.0", "ts-dedent": "^2.2.0" }, "engines": { - "node": "12.x || 14.x || >= 16" + "node": ">= 18" }, "peerDependencies": { "eslint": ">=6" @@ -28425,14 +28426,14 @@ } }, "eslint-plugin-storybook": { - "version": "0.6.15", - "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.6.15.tgz", - "integrity": "sha512-lAGqVAJGob47Griu29KXYowI4G7KwMoJDOkEip8ujikuDLxU+oWJ1l0WL6F2oDO4QiyUFXvtDkEkISMOPzo+7w==", + "version": "0.8.0", + "resolved": "https://nexus.tools.services.qld.gov.au/nexus/repository/npm_all/eslint-plugin-storybook/-/eslint-plugin-storybook-0.8.0.tgz", + "integrity": "sha512-CZeVO5EzmPY7qghO2t64oaFM+8FTaD4uzOEjHKp516exyTKo+skKAL9GI3QALS2BXhyALJjNtwbmr1XinGE8bA==", "dev": true, "requires": { "@storybook/csf": "^0.0.1", - "@typescript-eslint/utils": "^5.45.0", - "requireindex": "^1.1.0", + "@typescript-eslint/utils": "^5.62.0", + "requireindex": "^1.2.0", "ts-dedent": "^2.2.0" }, "dependencies": { diff --git a/package.json b/package.json index 46145a0cd..dfcd1cde0 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "watch": "node build.js --watch", "serve": "live-server dist", "storybook": "storybook dev -p 6006", - "build-storybook": "storybook build" + "build-storybook": "storybook build", + "lint": "eslint --fix --ext .js,.md,.mdx,.json ." }, "keywords": [], "author": "", diff --git a/src/components/bs5/banner/banner.stories.js b/src/components/bs5/banner/banner.stories.js index 345aa976e..e76a1b2f6 100644 --- a/src/components/bs5/banner/banner.stories.js +++ b/src/components/bs5/banner/banner.stories.js @@ -19,8 +19,8 @@ export default { export const Default = { args: { ...defaultdata, - breadcrumbs: "" - } + breadcrumbs: "", + }, }; // Default Breadcrumbs story @@ -28,6 +28,6 @@ const breadcrumbs = new Breadcrumbs(breadcrumbdata); export const WithBreadcrumbs = { args: { ...defaultdata, - breadcrumbs: breadcrumbs.html - } -} \ No newline at end of file + breadcrumbs: breadcrumbs.html, + }, +} diff --git a/src/components/bs5/blockquote/Blockquote.stories.js b/src/components/bs5/blockquote/Blockquote.stories.js index 223d2655b..2b8101492 100644 --- a/src/components/bs5/blockquote/Blockquote.stories.js +++ b/src/components/bs5/blockquote/Blockquote.stories.js @@ -10,5 +10,5 @@ export default { // Default blockquote story export const Default = { - args: defaultdata + args: defaultdata, }; diff --git a/src/components/bs5/globalAlert/GlobalAlert.stories.js b/src/components/bs5/globalAlert/GlobalAlert.stories.js index b68d9cd41..5210e1c38 100644 --- a/src/components/bs5/globalAlert/GlobalAlert.stories.js +++ b/src/components/bs5/globalAlert/GlobalAlert.stories.js @@ -16,7 +16,7 @@ export default { "global-alert-warning": "Warning", "global-alert-info": "General information", "global-alert-multiple": "Multiple", - } + }, }, options: ["global-alert-critical", "global-alert-warning", "global-alert-info", "global-alert-multiple"], }, diff --git a/src/components/bs5/sidenav/data.json b/src/components/bs5/sidenav/data.json index 9e26dfeeb..0967ef424 100644 --- a/src/components/bs5/sidenav/data.json +++ b/src/components/bs5/sidenav/data.json @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/src/components/bs5/tag/Tag.stories.js b/src/components/bs5/tag/Tag.stories.js index 26cec4d0b..e5e72dd6e 100644 --- a/src/components/bs5/tag/Tag.stories.js +++ b/src/components/bs5/tag/Tag.stories.js @@ -16,7 +16,7 @@ export default { "tag-alt": "Alt", "tag-dark": "Dark", "tag-dark-alt": "Dark-alt", - } + }, }, options: ["tag-default", "tag-alt", "tag-dark", "tag-dark-alt"], },