-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (126 loc) · 4.35 KB
/
get-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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@v4
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 }}