diff --git a/.github/workflows/ci.yml b/.github/workflows/check.yml similarity index 53% rename from .github/workflows/ci.yml rename to .github/workflows/check.yml index ede1ee398..0d986c325 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,4 @@ -name: ci +name: check on: push: @@ -17,7 +17,7 @@ concurrency: jobs: version: name: Ensure package version match - if: startsWith(github.ref, 'refs/tags/v') + if: startsWith(github.ref_name, 'v') runs-on: ubuntu-latest steps: - name: Checkout @@ -25,6 +25,14 @@ jobs: 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 @@ -82,7 +90,7 @@ jobs: fi check: - name: Build & Lint & Tests + name: Build & Lint & Test needs: version if: always() && (needs.version.result == 'success' || needs.version.result == 'skipped') runs-on: ubuntu-latest @@ -124,116 +132,3 @@ jobs: - 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 }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7046c1926..b9ddcd53a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,9 +2,11 @@ name: codeql on: push: - branches: [master] + branches: + - master pull_request: - branches: [master] + branches: + - master schedule: - cron: "0 0 * * 0" @@ -23,7 +25,8 @@ jobs: strategy: fail-fast: false matrix: - language: [javascript] + language: + - javascript steps: - name: Checkout repository uses: actions/checkout@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..eeadeae2a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +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" + 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..2ab0aa4e9 --- /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 8131f8abf..fe983f73d 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,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/shim.d.ts && npx shx cp ./src/shim.ts ./build/typings && npx ts-node ./scripts/package.json.ts --on root", + "postbuild": "npx shx rm ./build/typings/shim.d.ts && npx shx cp ./src/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`);