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

Tune Our GitHub Workflows #173

Merged
merged 30 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
02c8d42
ci: Add get-engines.yml
mmichaelis Dec 7, 2023
1ee8ee5
ci: Add build.yml
mmichaelis Dec 7, 2023
c69cdbe
ci: get-engines - prefer raw-output
mmichaelis Dec 7, 2023
312f520
ci: build - Authorize Towards Repository
mmichaelis Dec 7, 2023
c527b5b
ci: Playground - Propagate Secrets
mmichaelis Dec 7, 2023
ddeeb82
ci: Build - Tune NPM Authorization
mmichaelis Dec 7, 2023
9935add
ci: Build - Tune NPM Authorization
mmichaelis Dec 7, 2023
26deaf7
ci: get-engines - add verbose toggle
mmichaelis Dec 7, 2023
6b1f5e9
ci: Add Lint Workflow
mmichaelis Dec 8, 2023
1b3b816
ci: Move Linting and more
mmichaelis Dec 8, 2023
2c5bb41
ci: Minor Build Workflow Tuning
mmichaelis Dec 8, 2023
05bd048
ci: Add TypeDoc PoC
mmichaelis Dec 8, 2023
392f9cb
ci: Move Generating Doc to "Build"
mmichaelis Dec 8, 2023
e85d8a3
ci: Generate documentation artifact
mmichaelis Dec 8, 2023
b0a78ab
ci: Keep Documentation Artifact for 10 days only
mmichaelis Dec 8, 2023
6dbab51
ci: Add NODE_OPTIONS to build job
mmichaelis Dec 8, 2023
20b12c9
ci: Add timeout to build job
mmichaelis Dec 8, 2023
6111cd2
ci: Restrict Permissions for Build
mmichaelis Dec 8, 2023
3f88b3b
ci: Create On-Pull-Request Trigger
mmichaelis Dec 8, 2023
596016f
ci: Draft some summary report
mmichaelis Dec 8, 2023
428933e
ci: Remove Extra Output Job
mmichaelis Dec 8, 2023
117cc07
ci: Some more experimental output
mmichaelis Dec 8, 2023
dd994c5
ci: Limit Steps When Pull Request is Draft
mmichaelis Dec 8, 2023
24423e2
ci: Change Name for On Pull Request Push
mmichaelis Dec 8, 2023
2d5a609
ci: Extract Version Calculation
mmichaelis Dec 8, 2023
f5b61a5
ci: Adjust Version Calculation
mmichaelis Dec 8, 2023
962f127
ci: Fix PR Number Calculation
mmichaelis Dec 8, 2023
846ae31
ci: Fix Error Message Output
mmichaelis Dec 8, 2023
2f77cc5
ci: Use sed to extract PR-number
mmichaelis Dec 8, 2023
3cf5234
ci: Use Old Approach for PR-Number
mmichaelis Dec 8, 2023
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
159 changes: 159 additions & 0 deletions .github/workflows/build.yml
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
65 changes: 65 additions & 0 deletions .github/workflows/get-engines.yml
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
129 changes: 129 additions & 0 deletions .github/workflows/get-version.yml
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 }}
Loading