-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from CoreMedia/refactor-github-workflows
Tune Our GitHub Workflows
- Loading branch information
Showing
5 changed files
with
417 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
name: "Build" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
lint: | ||
description: "Linter" | ||
type: boolean | ||
required: false | ||
default: false | ||
utest: | ||
description: "Unit Tests" | ||
type: boolean | ||
required: false | ||
default: false | ||
itest: | ||
description: "Integration Tests" | ||
type: boolean | ||
required: false | ||
default: false | ||
# doc: Just used to "test the documentation", if it would build. | ||
# Helps to identify, for example, access to yet private API from | ||
# public API. | ||
doc: | ||
description: "Build Documentation (No Publish)" | ||
type: boolean | ||
required: false | ||
default: false | ||
workflow_call: | ||
inputs: | ||
lint: | ||
description: "Linter" | ||
type: boolean | ||
required: false | ||
default: false | ||
utest: | ||
description: "Unit Tests" | ||
type: boolean | ||
required: false | ||
default: false | ||
itest: | ||
description: "Integration Tests" | ||
type: boolean | ||
required: false | ||
default: false | ||
doc: | ||
description: "Build Documentation (No Publish)" | ||
type: boolean | ||
required: false | ||
default: false | ||
secrets: | ||
CM_NPM_USER: | ||
required: true | ||
CM_NPM_PASSWORD: | ||
required: true | ||
|
||
run-name: | | ||
${{ github.workflow }} (lint: ${{ github.event.inputs.lint }}, utest: ${{ github.event.inputs.utest }}, itest: ${{ github.event.inputs.itest }}) | ||
env: | ||
# https://github.com/actions/runner-images/issues/70 | ||
NODE_OPTIONS: "--max_old_space_size=4096" | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
get-env: | ||
name: "Get Environment" | ||
uses: "./.github/workflows/env.yml" | ||
get-engines: | ||
name: "Get Engines" | ||
uses: "./.github/workflows/get-engines.yml" | ||
secrets: inherit | ||
main: | ||
name: "Main" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
needs: | ||
- get-env | ||
- get-engines | ||
env: | ||
nodeVersion: ${{ needs.get-engines.outputs.nodeVersion }} | ||
pnpmVersion: ${{ needs.get-engines.outputs.pnpmVersion }} | ||
npmHost: ${{ needs.get-env.outputs.npm-host }} | ||
npmUrl: ${{ needs.get-env.outputs.npm-url }} | ||
steps: | ||
- id: checkout | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
- id: authorize | ||
name: "NPM Authorization" | ||
run: | | ||
result=$(curl -s -H "Accept: application/json" -H "Content-Type:application/json" -X PUT --data '{"name": "${{ secrets.CM_NPM_USER }}", "password": "${{ secrets.CM_NPM_PASSWORD }}"}' "${{ env.npmUrl }}/-/user/org.couchdb.user:${{ secrets.CM_NPM_USER }}" | jq --raw-output .token) | ||
# Ensure, the token is not exposed in output. | ||
echo "::add-mask::${result}" | ||
echo "NODE_AUTH_TOKEN=${result}" >> $GITHUB_ENV | ||
- id: initNpmConfiguration | ||
name: "Initialize NPM Configuration" | ||
run: | | ||
npmHost="${{ env.npmHost }}" | ||
npmUrl="${{ env.npmUrl }}" | ||
npmAuthToken="${{ env.NODE_AUTH_TOKEN }}" | ||
echo "//${npmHost}/:_authToken=${npmAuthToken}" >> .npmrc | ||
echo "@coremedia:registry=${npmUrl}" >> .npmrc | ||
# We must not commit this change. | ||
git update-index --assume-unchanged .npmrc | ||
- id: installPnpm | ||
name: "Install: Use PNPM ${{ env.pnpmVersion }}" | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ${{ env.pnpmVersion }} | ||
run_install: false | ||
- id: installNodeJs | ||
name: "Install: Use Node.js ${{ env.nodeVersion }}" | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.nodeVersion }} | ||
cache: "pnpm" | ||
- id: install | ||
name: Install | ||
run: | | ||
pnpm install --frozen-lockfile | ||
- id: build | ||
name: "Build" | ||
run: | | ||
pnpm -r build | ||
# To move the below steps to reusable workflow, we would need to be able | ||
# to share artifacts (downloaded dependencies as well as built artifacts). | ||
# Skipping for now. Instead, an outer workflow may run jobs in parallel, | ||
# with some extra effort that all of them need to set up authentication, | ||
# build, etc. | ||
- id: lint | ||
if: ${{ inputs.lint }} | ||
name: "Lint" | ||
run: | | ||
pnpm -r build | ||
- id: utest | ||
if: ${{ inputs.utest }} | ||
name: "Unit Tests" | ||
run: | | ||
pnpm jest | ||
- id: itest | ||
if: ${{ inputs.itest }} | ||
name: "Integration Tests" | ||
run: | | ||
pnpm playwright | ||
- id: doc | ||
if: ${{ inputs.doc }} | ||
name: "Build Documentation" | ||
run: | | ||
pnpm doc | ||
- name: Add Documentation Artifact | ||
if: ${{ inputs.doc }} | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: api-doc | ||
path: docs/ | ||
retention-days: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Retrieves engine information form package.json | ||
# | ||
# On manual call outputs the versions found. | ||
# On reusable workflow call provides version information as | ||
# `nodeVersion` and `pnpmVersion`. | ||
|
||
name: get-engines | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
verbose: | ||
description: "If to output the resulting versions as summary." | ||
required: false | ||
type: boolean | ||
default: false | ||
workflow_call: | ||
inputs: | ||
verbose: | ||
required: false | ||
type: boolean | ||
default: false | ||
outputs: | ||
nodeVersion: | ||
description: "Determined node version from package.json" | ||
value: ${{ jobs.main.outputs.nodeVersion }} | ||
pnpmVersion: | ||
description: "Determined pnpm version from package.json" | ||
value: ${{ jobs.main.outputs.pnpmVersion }} | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
main: | ||
name: "Get Engine Information" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
outputs: | ||
nodeVersion: ${{ steps.get-node-version.outputs.result }} | ||
pnpmVersion: ${{ steps.get-pnpm-version.outputs.result }} | ||
steps: | ||
- id: checkout | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
sparse-checkout: ./package.json | ||
- id: get-node-version | ||
name: "Get Node.js version" | ||
run: | | ||
result=$(cat package.json | jq --raw-output ".engines.node") | ||
echo "result=${result}" >> $GITHUB_OUTPUT | ||
- id: get-pnpm-version | ||
name: "Get PNPM version" | ||
run: | | ||
result=$(cat package.json | jq --raw-output ".engines.pnpm") | ||
echo "result=${result}" >> $GITHUB_OUTPUT | ||
- id: output-results | ||
if: ${{ inputs.verbose }} | ||
name: "Output Results" | ||
run: | | ||
echo "# Detected Engines" >> $GITHUB_STEP_SUMMARY | ||
echo "" >> $GITHUB_STEP_SUMMARY | ||
echo "* Node Version: ${{ steps.get-node-version.outputs.result }}" >> $GITHUB_STEP_SUMMARY | ||
echo "* PNPM Version: ${{ steps.get-pnpm-version.outputs.result }}" >> $GITHUB_STEP_SUMMARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
name: "Get Version" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: 'Release type.' | ||
required: true | ||
default: 'patch' | ||
type: choice | ||
options: | ||
- major | ||
- minor | ||
- patch | ||
- release-candidate | ||
- pull-request | ||
- current | ||
verbose: | ||
description: "If to output the resulting versions as summary." | ||
required: false | ||
type: boolean | ||
default: false | ||
workflow_call: | ||
inputs: | ||
release_type: | ||
description: 'Release type.' | ||
required: true | ||
default: 'patch' | ||
type: string | ||
verbose: | ||
description: "If to output the resulting versions as summary." | ||
required: false | ||
type: boolean | ||
default: false | ||
outputs: | ||
version: | ||
description: "The determined version." | ||
value: ${{ jobs.main.outputs.version }} | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
get-engines: | ||
uses: "./.github/workflows/get-engines.yml" | ||
secrets: inherit | ||
main: | ||
name: "Main" | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 5 | ||
needs: | ||
- get-engines | ||
env: | ||
nodeVersion: ${{ needs.get-engines.outputs.nodeVersion }} | ||
pnpmVersion: ${{ needs.get-engines.outputs.pnpmVersion }} | ||
steps: | ||
- id: checkout | ||
name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 1 | ||
sparse-checkout: | | ||
./package.json | ||
./.release-version | ||
./scripts | ||
- id: installPnpm | ||
name: "Install: Use PNPM ${{ env.pnpmVersion }}" | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ${{ env.pnpmVersion }} | ||
run_install: false | ||
- id: installNodeJs | ||
name: "Install: Use Node.js ${{ env.nodeVersion }}" | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ env.nodeVersion }} | ||
cache: "pnpm" | ||
- id: install | ||
name: Install | ||
run: | | ||
# We only need dev dependencies in root `package.json` | ||
pnpm install --frozen-lockfile --dev --filter "@coremedia/ckeditor5" | ||
- id: for-release | ||
name: "Version for Release" | ||
if: ${{ inputs.release_type == 'major' || inputs.release_type == 'minor' || inputs.release_type == 'patch' }} | ||
run: | | ||
version=$(pnpm --silent "script:version" --release ${{ inputs.release_type }}) | ||
echo "VERSION=${version}" >> $GITHUB_ENV | ||
- id: for-release-candidate | ||
name: "Version for Release Candidate" | ||
if: ${{ inputs.release_type == 'release-candidate' }} | ||
run: | | ||
version=$(pnpm --silent "script:version" --release-candidate) | ||
echo "VERSION=${version}" >> $GITHUB_ENV | ||
- id: for-current | ||
name: "Current Version" | ||
if: ${{ inputs.release_type == 'current' }} | ||
run: | | ||
version=$(pnpm --silent "script:version" --current) | ||
echo "VERSION=${version}" >> $GITHUB_ENV | ||
- id: for-pull-request | ||
name: "Version for Pull Request" | ||
if: ${{ inputs.release_type == 'pull-request' }} | ||
run: | | ||
run="${{ github.run_number }}" | ||
# Parsing just github.ref, for example, does not seem to work in | ||
# all scenarios. | ||
pullRequestNumber=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{github.repository}}/pulls?head=${{github.repository_owner}}:${{github.ref}} | jq -r '.[] | .number' ) | ||
version=$(pnpm --silent "script:version" --pull-request ${pullRequestNumber} --run-number ${run}) | ||
echo "VERSION=${version}" >> $GITHUB_ENV | ||
- id: unmatched-release-type | ||
name: "On Unmatched Release Type" | ||
if: ${{ !env.VERSION }} | ||
run: | | ||
echo "::error::Invalid release-type: ${{ inputs.release_type }}" | ||
exit 1 | ||
- id: output-version | ||
name: "Output Version" | ||
if: ${{ env.VERSION }} | ||
run: | | ||
echo "version=${{ env.VERSION }}" >> $GITHUB_OUTPUT | ||
- id: summary | ||
if: ${{ inputs.verbose }} | ||
name: "Output Version Summary" | ||
run: | | ||
echo "# Version" >> $GITHUB_STEP_SUMMARY | ||
echo "" >> $GITHUB_STEP_SUMMARY | ||
echo "Version for ${{ inputs.release_type }}: ${{ steps.output-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY | ||
outputs: | ||
version: ${{ steps.output-version.outputs.version }} |
Oops, something went wrong.