Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(workflow): split ci workflow in multiple workflows & fix regex #1501

Merged
merged 5 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 11 additions & 116 deletions .github/workflows/ci.yml → .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci
name: check

on:
push:
Expand All @@ -17,14 +17,22 @@ 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
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
9 changes: 6 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: codeql

on:
push:
branches: [master]
branches:
- master
pull_request:
branches: [master]
branches:
- master
schedule:
- cron: "0 0 * * 0"

Expand All @@ -23,7 +25,8 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [javascript]
language:
- javascript
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
49 changes: 49 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*\"",
Expand Down
Loading