From 8147eed146784d696d2c024ac75e8fab62a21a4c Mon Sep 17 00:00:00 2001 From: Carlo Corradini Date: Tue, 22 Aug 2023 12:24:33 +0200 Subject: [PATCH 1/4] chore(workflow): split ci workflow in multiple workflows & fix regex --- .github/workflows/{ci.yml => check.yml} | 373 +++++++++--------------- .github/workflows/codeql.yml | 83 +++--- .github/workflows/release.yml | 94 ++++++ .github/workflows/website.yml | 49 ++++ README.md | 3 +- package.json | 2 +- scripts/markdown.ts | 30 +- 7 files changed, 341 insertions(+), 293 deletions(-) rename .github/workflows/{ci.yml => check.yml} (52%) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/website.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/check.yml similarity index 52% rename from .github/workflows/ci.yml rename to .github/workflows/check.yml index ede1ee398..c2d2f754e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/check.yml @@ -1,239 +1,134 @@ -name: ci - -on: - push: - branches: - - master - tags: - - v* - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - version: - name: Ensure package version match - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Read package.json version - uses: sergeysova/jq-action@v2 - id: version_package - with: - cmd: jq --raw-output .version package.json - - - name: Read GitHub version - uses: pozetroninc/github-action-get-latest-release@master - id: version_v_github - with: - owner: MichalLytek - repo: type-graphql - excludes: prerelease, draft - - - name: Remove leading v* from GitHub version - id: version_github - run: | - _version="${{ steps.version_v_github.outputs.release }}" - printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" - - - name: Read Git tag version - id: version_gittag - run: | - _version="${{ github.ref_name }}" - printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" - - - name: Compare package.json with Git tag - uses: madhead/semver-utils@latest - id: comparison_package_gittag - with: - version: ${{ steps.version_package.outputs.value }} - compare-to: ${{ steps.version_gittag.outputs.value }} - lenient: false - - - name: Compare Git tag with GitHub - uses: madhead/semver-utils@latest - id: comparison_gittag_github - with: - version: ${{ steps.version_gittag.outputs.value }} - compare-to: ${{ steps.version_github.outputs.value }} - lenient: false - - - name: Check package.json == Git tag - run: | - if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then - printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}" - exit 1 - fi - - - name: Check Git tag > GitHub - run: | - if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then - printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}" - exit 1 - fi - - check: - name: Build & Lint & Tests - needs: version - if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped') - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - node-version: [16.x, 18.x, 20.x] - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Dependencies - run: | - npm ci - - - name: Build - run: | - npm run build - npm run build:benchmarks - - - name: Check - run: | - npm run check - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Test - run: npm run test:ci - env: - CI: true - - - name: Upload code coverage - uses: codecov/codecov-action@v3 - if: matrix.node-version == '18.x' - - release: - name: Release package on NPM - needs: check - if: needs.check.result == 'success' && startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - permissions: - contents: write - id-token: write - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Read package.json version - uses: sergeysova/jq-action@v2 - id: version - with: - cmd: jq --raw-output .version package.json - - - name: Determine if version is prerelease - id: prerelease - run: | - _prerelease= - if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then - _prerelease=false - else - _prerelease=true - fi - - printf 'value=%s\n' "$_prerelease" >> "$GITHUB_OUTPUT" - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - registry-url: "https://registry.npmjs.org" - - - name: Install latest npm - run: | - npm install -g npm@latest - - - name: Install Dependencies - run: | - npm ci - - - name: Prepare package - run: | - npm run prepublishOnly - env: - TYPE_GRAPHQL_REF: ${{ github.ref_name }} - - - name: Build Changelog - id: changelog - uses: mikepenz/release-changelog-builder-action@v4 - with: - configuration: "./.github/configs/changelog.json" - owner: MichalLytek - repo: type-graphql - failOnError: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Release - uses: softprops/action-gh-release@v1 - with: - body: ${{ steps.changelog.outputs.changelog }} - prerelease: ${{ steps.prerelease.outputs.value == 'true' }} - - - name: Publish - run: | - _tag= - if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then - _tag="next" - else - _tag="latest" - fi - - npm publish --ignore-scripts --tag "$_tag" - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - website: - name: Publish website - needs: check - if: always() && github.ref == 'refs/heads/master' - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - - - name: Install Dependencies - run: | - npm ci - npm ci --prefix ./website - - - name: Build - run: | - npm run build --prefix ./website - - - name: Publish - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./website/build/type-graphql - user_name: "github-actions[bot]" - user_email: "github-actions[bot]@users.noreply.github.com" - full_commit_message: | - Deploy website based on ${{ github.sha }} +name: check + +on: + push: + branches: + - master + tags: + - "^v*" + pull_request: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + version: + name: Ensure package version match + if: startsWith(github.ref_name, 'v') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Check Git tag format + run: | + _tag="${{ github.ref_name }}" + if ! printf "%s\n" "$_tag" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then + printf '[ERROR]: Git tag (%s) wrong format\n' "$_tag" + exit 1 + fi + + - name: Read package.json version + uses: sergeysova/jq-action@v2 + id: version_package + with: + cmd: jq --raw-output .version package.json + + - name: Read GitHub version + uses: pozetroninc/github-action-get-latest-release@master + id: version_v_github + with: + owner: MichalLytek + repo: type-graphql + excludes: prerelease, draft + + - name: Remove leading v* from GitHub version + id: version_github + run: | + _version="${{ steps.version_v_github.outputs.release }}" + printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" + + - name: Read Git tag version + id: version_gittag + run: | + _version="${{ github.ref_name }}" + printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" + + - name: Compare package.json with Git tag + uses: madhead/semver-utils@latest + id: comparison_package_gittag + with: + version: ${{ steps.version_package.outputs.value }} + compare-to: ${{ steps.version_gittag.outputs.value }} + lenient: false + + - name: Compare Git tag with GitHub + uses: madhead/semver-utils@latest + id: comparison_gittag_github + with: + version: ${{ steps.version_gittag.outputs.value }} + compare-to: ${{ steps.version_github.outputs.value }} + lenient: false + + - name: Check package.json == Git tag + run: | + if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then + printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}" + exit 1 + fi + + - name: Check Git tag > GitHub + run: | + if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then + printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}" + exit 1 + fi + + check: + name: Build & Lint & Test + needs: version + if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped') + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + node-version: [16.x, 18.x, 20.x] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: | + npm ci + + - name: Build + run: | + npm run build + npm run build:benchmarks + + - name: Check + run: | + npm run check + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Test + run: npm run test:ci + env: + CI: true + + - name: Upload code coverage + uses: codecov/codecov-action@v3 + if: matrix.node-version == '18.x' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7046c1926..f6336b76d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,40 +1,43 @@ -name: codeql - -on: - push: - branches: [master] - pull_request: - branches: [master] - schedule: - - cron: "0 0 * * 0" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - strategy: - fail-fast: false - matrix: - language: [javascript] - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - config-file: ./.github/configs/codeql.yml - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 +name: codeql + +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + - cron: "0 0 * * 0" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: + - javascript + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + config-file: ./.github/configs/codeql.yml + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..5e207a647 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,94 @@ +name: release + +on: + workflow_run: + workflows: + - check + types: + - completed + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + release: + name: Release package on NPM + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && startsWith(github.ref_name, 'v') + permissions: + contents: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Read package.json version + uses: sergeysova/jq-action@v2 + id: version + with: + cmd: jq --raw-output .version package.json + + - name: Determine if version is prerelease + id: prerelease + run: | + _prerelease= + if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then + _prerelease=false + else + _prerelease=true + fi + + printf 'value=%s\n' "$_prerelease" >> "$GITHUB_OUTPUT" + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + registry-url: "https://registry.npmjs.org" + + - name: Install latest npm + run: | + npm install -g npm@latest + + - name: Install Dependencies + run: | + npm ci + + - name: Prepare package + run: | + npm run prepublishOnly + env: + TYPE_GRAPHQL_REF: ${{ github.ref_name }} + + - name: Build Changelog + id: changelog + uses: mikepenz/release-changelog-builder-action@v4 + with: + configuration: "./.github/configs/changelog.json" + owner: MichalLytek + repo: type-graphql + failOnError: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + body: ${{ steps.changelog.outputs.changelog }} + prerelease: ${{ steps.prerelease.outputs.value == 'true' }} + + - name: Publish + run: | + _tag= + if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then + _tag="next" + else + _tag="latest" + fi + + npm publish --ignore-scripts --tag "$_tag" + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 000000000..db3826e33 --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,49 @@ +name: website + +on: + workflow_run: + workflows: + - check + types: + - completed + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + website: + name: Publish website + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + + - name: Install Dependencies + run: | + npm ci + npm ci --prefix ./website + + - name: Build + run: | + npm run build --prefix ./website + + - name: Publish + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./website/build/type-graphql + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" + full_commit_message: | + Deploy website based on ${{ github.sha }} diff --git a/README.md b/README.md index 0f77f2cd2..063e8af56 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ # TypeGraphQL -[![ci](https://github.com/MichalLytek/type-graphql/actions/workflows/ci.yml/badge.svg)](https://github.com/MichalLytek/type-graphql/actions/workflows/ci.yml) +[![release](https://github.com/MichalLytek/type-graphql/actions/workflows/release.yml/badge.svg)](https://github.com/MichalLytek/type-graphql/actions/workflows/release.yml) +[![website](https://github.com/MichalLytek/type-graphql/actions/workflows/website.yml/badge.svg)](https://github.com/MichalLytek/type-graphql/actions/workflows/website.yml) [![codeql](https://github.com/MichalLytek/type-graphql/actions/workflows/codeql.yml/badge.svg)](https://github.com/carlocorradini/reCluster/actions/workflows/codeql.yml) [![npm version](https://badge.fury.io/js/type-graphql.svg)](https://badge.fury.io/js/type-graphql) [![codecov](https://codecov.io/gh/MichalLytek/type-graphql/branch/master/graph/badge.svg)](https://codecov.io/gh/MichalLytek/type-graphql) diff --git a/package.json b/package.json index 44a727413..a32f6224a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "scripts": { "prebuild": "npm run clean:build && npm run check:version", "build": "npx tsc --build ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.typings.json", - "postbuild": "npx shx rm ./build/typings/browser-shim.d.ts && npx shx cp ./src/browser-shim.ts ./build/typings && npx ts-node ./scripts/package.json.ts --on root", + "postbuild": "npx shx rm ./build/typings/browser-shim.d.ts && npx shx cp ./src/browser-shim.ts ./build/typings && npx ts-node ./scripts/package.json.ts", "prebuild:benchmarks": "npm run clean:build:benchmarks", "build:benchmarks": "npx tsc --build ./benchmarks/tsconfig.json", "check": "npx npm-run-all --npm-path npm \"check:*\"", diff --git a/scripts/markdown.ts b/scripts/markdown.ts index baaadd8b1..2c0b6bb73 100644 --- a/scripts/markdown.ts +++ b/scripts/markdown.ts @@ -19,7 +19,7 @@ function escapeRegExp(string: string): string { return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); } -const enum ANALYZE { +const enum Analyze { DOCS = "docs", README = "readme", } @@ -30,31 +30,37 @@ const rootPath = path.resolve(`${__dirname}/..`); const argv = yargs(hideBin(process.argv)) .strict() .env("TYPE_GRAPHQL") - .usage("Markdown\n\nUsage: $0 [options]") + .usage("Markdown\n\nUsage: $0 --ref [options]") .example([ - ["$0", "Use 'master' as Git reference"], ["$0 --ref v1.2.3", "Use 'v1.2.3' as Git reference"], ["TYPE_GRAPHQL_REF=v1.2.3 $0", "Use 'v1.2.3' as Git reference"], - [`$0 --on ${ANALYZE.README}`, `Analyze '${ANALYZE.README}'`], [ - `$0 --on ${ANALYZE.README} ${ANALYZE.DOCS}`, - `Analyze '${ANALYZE.README}' and '${ANALYZE.DOCS}'`, + `$0 --ref v1.2.3 --on ${Analyze.README}`, + `Use 'v1.2.3' as Git reference and analyze '${Analyze.README}'`, + ], + [ + `$0 --ref v1.2.3 --on ${Analyze.README} ${Analyze.DOCS}`, + `Use 'v1.2.3' as Git reference and analyze '${Analyze.README}' and '${Analyze.DOCS}'`, ], ]) .option("ref", { type: "string", - default: "master", + demandOption: true, description: "Git reference", }) .option("on", { type: "array", - default: [] as ANALYZE[], + default: [] as Analyze[], requiresArg: true, - choices: [ANALYZE.DOCS, ANALYZE.README], + choices: [Analyze.DOCS, Analyze.README], description: "Analysis to be performed", }) .check(({ ref, on }) => { - if (!/^v[0-9]+.[0-9]+.[0-9]+(-(alpha|beta|rc)\.[0-9]+)*$/.test(ref)) { + if ( + !/^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$/.test( + ref, + ) + ) { throw new Error(`Invalid Git reference '${ref}'`); } if (on.length === 0) { @@ -68,7 +74,7 @@ const gitHubUrlRef = `${gitHubUrl}/${argv.ref}`; const gitHubUrlRawRef = `${gitHubUrlRaw}/${argv.ref}`; // README.md -if (argv.on.includes(ANALYZE.README)) { +if (argv.on.includes(Analyze.README)) { const readmeFile = path.resolve(`${rootPath}/README.md`); const readme = fs @@ -98,7 +104,7 @@ if (argv.on.includes(ANALYZE.README)) { } // docs/**/*.md -if (argv.on.includes(ANALYZE.DOCS)) { +if (argv.on.includes(Analyze.DOCS)) { const docFiles = glob.globSync(`${rootPath}/docs/**/*.md`, { absolute: true }); const gitHubUrlRefMasterEscaped = escapeRegExp(`${gitHubUrl}/master`); From c1d85d022416aca0b0c8a68be3ca74312132586b Mon Sep 17 00:00:00 2001 From: carlocorradini Date: Tue, 22 Aug 2023 22:05:50 +0200 Subject: [PATCH 2/4] chore(workflow): fix format --- .github/workflows/check.yml | 268 +++++++++++++++++----------------- .github/workflows/codeql.yml | 86 +++++------ .github/workflows/release.yml | 188 ++++++++++++------------ .github/workflows/website.yml | 98 ++++++------- 4 files changed, 320 insertions(+), 320 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c2d2f754e..e2f6cbd58 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,134 +1,134 @@ -name: check - -on: - push: - branches: - - master - tags: - - "^v*" - pull_request: - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - version: - name: Ensure package version match - if: startsWith(github.ref_name, 'v') - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Check Git tag format - run: | - _tag="${{ github.ref_name }}" - if ! printf "%s\n" "$_tag" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then - printf '[ERROR]: Git tag (%s) wrong format\n' "$_tag" - exit 1 - fi - - - name: Read package.json version - uses: sergeysova/jq-action@v2 - id: version_package - with: - cmd: jq --raw-output .version package.json - - - name: Read GitHub version - uses: pozetroninc/github-action-get-latest-release@master - id: version_v_github - with: - owner: MichalLytek - repo: type-graphql - excludes: prerelease, draft - - - name: Remove leading v* from GitHub version - id: version_github - run: | - _version="${{ steps.version_v_github.outputs.release }}" - printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" - - - name: Read Git tag version - id: version_gittag - run: | - _version="${{ github.ref_name }}" - printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" - - - name: Compare package.json with Git tag - uses: madhead/semver-utils@latest - id: comparison_package_gittag - with: - version: ${{ steps.version_package.outputs.value }} - compare-to: ${{ steps.version_gittag.outputs.value }} - lenient: false - - - name: Compare Git tag with GitHub - uses: madhead/semver-utils@latest - id: comparison_gittag_github - with: - version: ${{ steps.version_gittag.outputs.value }} - compare-to: ${{ steps.version_github.outputs.value }} - lenient: false - - - name: Check package.json == Git tag - run: | - if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then - printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}" - exit 1 - fi - - - name: Check Git tag > GitHub - run: | - if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then - printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}" - exit 1 - fi - - check: - name: Build & Lint & Test - needs: version - if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped') - runs-on: ubuntu-latest - strategy: - fail-fast: true - matrix: - node-version: [16.x, 18.x, 20.x] - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - - - name: Install Dependencies - run: | - npm ci - - - name: Build - run: | - npm run build - npm run build:benchmarks - - - name: Check - run: | - npm run check - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Test - run: npm run test:ci - env: - CI: true - - - name: Upload code coverage - uses: codecov/codecov-action@v3 - if: matrix.node-version == '18.x' +name: check + +on: + push: + branches: + - master + tags: + - "^v*" + pull_request: + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + version: + name: Ensure package version match + if: startsWith(github.ref_name, 'v') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Check Git tag format + run: | + _tag="${{ github.ref_name }}" + if ! printf "%s\n" "$_tag" | grep -q -P '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-(alpha|beta|rc)\.(0|[1-9][0-9]*))?$'; then + printf '[ERROR]: Git tag (%s) wrong format\n' "$_tag" + exit 1 + fi + + - name: Read package.json version + uses: sergeysova/jq-action@v2 + id: version_package + with: + cmd: jq --raw-output .version package.json + + - name: Read GitHub version + uses: pozetroninc/github-action-get-latest-release@master + id: version_v_github + with: + owner: MichalLytek + repo: type-graphql + excludes: prerelease, draft + + - name: Remove leading v* from GitHub version + id: version_github + run: | + _version="${{ steps.version_v_github.outputs.release }}" + printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" + + - name: Read Git tag version + id: version_gittag + run: | + _version="${{ github.ref_name }}" + printf 'value=%s\n' "${_version#?}" >> "$GITHUB_OUTPUT" + + - name: Compare package.json with Git tag + uses: madhead/semver-utils@latest + id: comparison_package_gittag + with: + version: ${{ steps.version_package.outputs.value }} + compare-to: ${{ steps.version_gittag.outputs.value }} + lenient: false + + - name: Compare Git tag with GitHub + uses: madhead/semver-utils@latest + id: comparison_gittag_github + with: + version: ${{ steps.version_gittag.outputs.value }} + compare-to: ${{ steps.version_github.outputs.value }} + lenient: false + + - name: Check package.json == Git tag + run: | + if [ ! "${{ steps.comparison_package_gittag.outputs.comparison-result }}" = "=" ]; then + printf '[ERROR]: package.json (%s) != Git tag (%s)\n' "${{ steps.version_package.outputs.value }}" "${{ steps.version_gittag.outputs.value }}" + exit 1 + fi + + - name: Check Git tag > GitHub + run: | + if [ ! "${{ steps.comparison_gittag_github.outputs.comparison-result }}" = ">" ]; then + printf '[ERROR]: Git tag (%s) !> GitHub (%s)\n' "${{ steps.version_gittag.outputs.value }}" "${{ steps.version_github.outputs.value }}" + exit 1 + fi + + check: + name: Build & Lint & Test + needs: version + if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped') + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + node-version: [16.x, 18.x, 20.x] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: | + npm ci + + - name: Build + run: | + npm run build + npm run build:benchmarks + + - name: Check + run: | + npm run check + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Test + run: npm run test:ci + env: + CI: true + + - name: Upload code coverage + uses: codecov/codecov-action@v3 + if: matrix.node-version == '18.x' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f6336b76d..b9ddcd53a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,43 +1,43 @@ -name: codeql - -on: - push: - branches: - - master - pull_request: - branches: - - master - schedule: - - cron: "0 0 * * 0" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - strategy: - fail-fast: false - matrix: - language: - - javascript - steps: - - name: Checkout repository - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - config-file: ./.github/configs/codeql.yml - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 +name: codeql + +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + - cron: "0 0 * * 0" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + strategy: + fail-fast: false + matrix: + language: + - javascript + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + config-file: ./.github/configs/codeql.yml + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5e207a647..b2e917d01 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,94 +1,94 @@ -name: release - -on: - workflow_run: - workflows: - - check - types: - - completed - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - release: - name: Release package on NPM - runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion == 'success' && startsWith(github.ref_name, 'v') - permissions: - contents: write - id-token: write - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Read package.json version - uses: sergeysova/jq-action@v2 - id: version - with: - cmd: jq --raw-output .version package.json - - - name: Determine if version is prerelease - id: prerelease - run: | - _prerelease= - if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then - _prerelease=false - else - _prerelease=true - fi - - printf 'value=%s\n' "$_prerelease" >> "$GITHUB_OUTPUT" - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - registry-url: "https://registry.npmjs.org" - - - name: Install latest npm - run: | - npm install -g npm@latest - - - name: Install Dependencies - run: | - npm ci - - - name: Prepare package - run: | - npm run prepublishOnly - env: - TYPE_GRAPHQL_REF: ${{ github.ref_name }} - - - name: Build Changelog - id: changelog - uses: mikepenz/release-changelog-builder-action@v4 - with: - configuration: "./.github/configs/changelog.json" - owner: MichalLytek - repo: type-graphql - failOnError: true - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Release - uses: softprops/action-gh-release@v1 - with: - body: ${{ steps.changelog.outputs.changelog }} - prerelease: ${{ steps.prerelease.outputs.value == 'true' }} - - - name: Publish - run: | - _tag= - if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then - _tag="next" - else - _tag="latest" - fi - - npm publish --ignore-scripts --tag "$_tag" - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} +name: release + +on: + workflow_run: + workflows: + - check + types: + - completed + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + release: + name: Release package on NPM + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' && startsWith(github.ref_name, 'v') + permissions: + contents: write + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Read package.json version + uses: sergeysova/jq-action@v2 + id: version + with: + cmd: jq --raw-output .version package.json + + - name: Determine if version is prerelease + id: prerelease + run: | + _prerelease= + if printf "%s\n" "${{ steps.version.outputs.value }}" | grep -q -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$'; then + _prerelease=false + else + _prerelease=true + fi + + printf 'value=%s\n' "$_prerelease" >> "$GITHUB_OUTPUT" + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + registry-url: "https://registry.npmjs.org" + + - name: Install latest npm + run: | + npm install -g npm@latest + + - name: Install Dependencies + run: | + npm ci + + - name: Prepare package + run: | + npm run prepublishOnly + env: + TYPE_GRAPHQL_REF: ${{ github.ref_name }} + + - name: Build Changelog + id: changelog + uses: mikepenz/release-changelog-builder-action@v4 + with: + configuration: "./.github/configs/changelog.json" + owner: MichalLytek + repo: type-graphql + failOnError: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release + uses: softprops/action-gh-release@v1 + with: + body: ${{ steps.changelog.outputs.changelog }} + prerelease: ${{ steps.prerelease.outputs.value == 'true' }} + + - name: Publish + run: | + _tag= + if [ "${{ steps.prerelease.outputs.value }}" = "true" ]; then + _tag="next" + else + _tag="latest" + fi + + npm publish --ignore-scripts --tag "$_tag" + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index db3826e33..2ab0aa4e9 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -1,49 +1,49 @@ -name: website - -on: - workflow_run: - workflows: - - check - types: - - completed - branches: - - master - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - website: - name: Publish website - runs-on: ubuntu-latest - if: github.event.workflow_run.conclusion == 'success' - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup Node.js - uses: actions/setup-node@v3 - with: - node-version: "18.x" - - - name: Install Dependencies - run: | - npm ci - npm ci --prefix ./website - - - name: Build - run: | - npm run build --prefix ./website - - - name: Publish - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./website/build/type-graphql - user_name: "github-actions[bot]" - user_email: "github-actions[bot]@users.noreply.github.com" - full_commit_message: | - Deploy website based on ${{ github.sha }} +name: website + +on: + workflow_run: + workflows: + - check + types: + - completed + branches: + - master + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + website: + name: Publish website + runs-on: ubuntu-latest + if: github.event.workflow_run.conclusion == 'success' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: "18.x" + + - name: Install Dependencies + run: | + npm ci + npm ci --prefix ./website + + - name: Build + run: | + npm run build --prefix ./website + + - name: Publish + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./website/build/type-graphql + user_name: "github-actions[bot]" + user_email: "github-actions[bot]@users.noreply.github.com" + full_commit_message: | + Deploy website based on ${{ github.sha }} From 90fe1eabfbc4f697893a8ba0c79a52e83580c5b6 Mon Sep 17 00:00:00 2001 From: carlocorradini Date: Thu, 24 Aug 2023 12:16:28 +0200 Subject: [PATCH 3/4] chore(workflow): remove invalid character --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e2f6cbd58..0d986c325 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -5,7 +5,7 @@ on: branches: - master tags: - - "^v*" + - v* pull_request: branches: - master From 68bcfdb0455d54deed36747ab9c46aef5b024987 Mon Sep 17 00:00:00 2001 From: carlocorradini Date: Thu, 24 Aug 2023 12:24:26 +0200 Subject: [PATCH 4/4] chore(workflow): remove useless config --- .github/workflows/release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b2e917d01..eeadeae2a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,8 +68,6 @@ jobs: uses: mikepenz/release-changelog-builder-action@v4 with: configuration: "./.github/configs/changelog.json" - owner: MichalLytek - repo: type-graphql failOnError: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}