-
Notifications
You must be signed in to change notification settings - Fork 4
175 lines (164 loc) · 8.93 KB
/
github-release.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Create GitHub release version and location
on:
workflow_call:
outputs:
release_version:
description: The computed release version for the release (or pre-release) being built
value: ${{ jobs.create-github-release.outputs.release_version }}
release_url:
description: The upload URL for build artifacts for this release
value: ${{ jobs.create-github-release.outputs.release_url }}
IS_FULL_RELEASE:
description: The upload URL for build artifacts for this release
value: ${{ jobs.create-github-release-workflow.outputs.IS_FULL_RELEASE }}
PR_BASE_TAG:
description: major.min version
value: ${{ jobs.create-github-release-workflow.outputs.PR_BASE_TAG }}
pull_request:
types: [opened, closed, edited, synchronize]
push:
jobs:
call-check-file-action:
uses: keyfactor/cpr-release-checks/.github/workflows/check-files.yml@main
create-github-release-workflow:
runs-on: ubuntu-latest
outputs:
PR_BASE_REF: ${{ steps.set-outputs.outputs.PR_BASE_REF }}
PR_COMMIT_SHA: ${{ steps.set-outputs.outputs.PR_COMMIT_SHA }}
GITHUB_SHA: ${{ steps.set-outputs.outputs.GITHUB_SHA }}
PR_BASE_TAG: ${{ steps.set-outputs.outputs.PR_BASE_TAG }}
IS_FULL_RELEASE: ${{ steps.set-outputs.outputs.IS_FULL_RELEASE }}
IS_PRE_RELEASE: ${{ steps.set-outputs.outputs.IS_PRE_RELEASE }}
INC_LEVEL: ${{ steps.set-outputs.outputs.INC_LEVEL }}
IS_RELEASE_BRANCH: ${{ steps.set-outputs.outputs.IS_RELEASE_BRANCH }}
IS_HOTFIX: ${{ steps.set-outputs.outputs.IS_HOTFIX }}
LATEST_TAG: ${{ steps.set-outputs.outputs.LATEST_TAG }}
steps:
- name: Check out the code
uses: keyfactor/checkout@v4
- name: Display base.ref from Pull Request
if: github.event_name == 'pull_request'
id: display-from-pr
run: |
echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
echo "Event Action: ${{ github.event.action }}" | tee -a $GITHUB_STEP_SUMMARY
echo "PR_BASE_REF=${{ github.event.pull_request.base.ref }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
echo "PR_STATE=${{ github.event.pull_request.state }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
echo "PR_MERGED=${{ github.event.pull_request.merged }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
echo "PR_COMMIT_SHA=${{ github.event.pull_request.merge_commit_sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
echo "GITHUB_SHA=${{ github.sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
baseref="${{ github.event.pull_request.base.ref }}"
basetag="${baseref#release-}"
echo "PR_BASE_TAG=$basetag" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
- name: Display base_ref from Push Event
if: github.event_name == 'push'
id: display-from-push
run: |
echo "Branch Ref: ${{ github.ref }}" | tee -a $GITHUB_STEP_SUMMARY
echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
echo "github.sha: ${{ github.sha }}" | tee -a $GITHUB_STEP_SUMMARY
- name: Find Latest Tag
if: github.event_name == 'pull_request'
id: find-latest-tag
run: |
prbasetag="${{env.PR_BASE_TAG}}"
git fetch --tags
if [[ -n `git tag` ]]; then
echo "Setting vars"
allBranchTags=`git tag --sort=-v:refname | grep "^$prbasetag" || echo ""`
allRepoTags=`git tag --sort=-v:refname`
branchTagBase=`git tag --sort=-v:refname | grep "^$prbasetag" | grep -o '^[0-9.]*' | head -n 1 || echo ""`
latestTagBase=`git tag --sort=-v:refname | grep -o '^[0-9.]*' | head -n 1`
latestBranchTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase" | head -n 1 || echo ""`
latestReleasedTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase$" | head -n 1 || echo ""`
# If the *TagBase values are not found in the list of tags, it means no final release was produced, and the latest*Tag vars will be empty
if [[ -z "$latestReleasedTag" ]]; then
latestTag="$latestBranchTag"
else
latestTag="$latestReleasedTag"
fi
echo "LATEST_TAG=${latestTag}" | tee -a "$GITHUB_ENV"
if [[ "$latestTagBase" == *"$branchTagBase" ]]; then
hf="False"
else
hf="True"
fi
# The intention is to use this to set the make_latest:false property when
# dispatching the create-release action, but it is not *yet* a configurable option
echo "IS_HOTFIX=$hf" | tee -a "$GITHUB_ENV"
else
echo "No tags exist in this repo"
echo "LATEST_TAG=" | tee -a "$GITHUB_ENV"
fi
- name: Set Outputs
if: github.event_name == 'pull_request'
id: set-outputs
run: |
echo "PR_BASE_REF=${{ env.PR_BASE_REF }}" | tee -a "$GITHUB_OUTPUT"
echo "PR_STATE=${{ env.PR_STATE }}"
echo "PR_MERGED=${{ env.PR_MERGED }}"
if [[ "${{ env.PR_STATE }}" == "closed" && "${{ env.PR_MERGED }}" == "true" && "${{ env.PR_COMMIT_SHA }}" == "${{ env.GITHUB_SHA }}" ]]; then
echo "IS_FULL_RELEASE=True" | tee -a "$GITHUB_OUTPUT"
echo "INC_LEVEL=patch" | tee -a "$GITHUB_OUTPUT"
fi
if [[ "${{ env.PR_STATE }}" == "open" ]]; then
echo "IS_PRE_RELEASE=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
echo "INC_LEVEL=prerelease" | tee -a "$GITHUB_OUTPUT"
fi
if [[ "${{ env.PR_BASE_REF }}" == "release-"* ]]; then
echo "IS_RELEASE_BRANCH=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
fi
echo "PR_COMMIT_SHA=${{ env.PR_COMMIT_SHA }}" | tee -a "$GITHUB_OUTPUT"
echo "GITHUB_SHA=${{ env.GITHUB_SHA }}" | tee -a "$GITHUB_OUTPUT"
echo "PR_BASE_TAG=${{ env.PR_BASE_TAG }}" | tee -a "$GITHUB_OUTPUT"
echo "IS_HOTFIX=${{ env.IS_HOTFIX }}" | tee -a "$GITHUB_OUTPUT"
echo "LATEST_TAG=${{ env.LATEST_TAG }}" | tee -a "$GITHUB_OUTPUT"
create-github-release:
needs: create-github-release-workflow
if: github.event_name == 'pull_request' && needs.create-github-release-workflow.outputs.IS_RELEASE_BRANCH == 'True'
outputs:
release_version: ${{ steps.create_release.outputs.current_tag }}
release_url: ${{ steps.create_release.outputs.upload_url }}
runs-on: ubuntu-latest
steps:
- run: |
echo "INC_LEVEL=${{ needs.create-github-release-workflow.outputs.INC_LEVEL}}"
- name: Check if initial release
if: needs.create-github-release-workflow.outputs.LATEST_TAG == ''
run: |
echo "INITIAL_VERSION=${{needs.create-github-release-workflow.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_STEP_SUMMARY" | tee -a "$GITHUB_ENV"
echo "MANUAL_VERSION=${{needs.create-github-release-workflow.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_ENV"
- name: Set semver info
id: set-semver-info
if: needs.create-github-release-workflow.outputs.LATEST_TAG != ''
uses: keyfactor/action-bump-semver@v1
with:
current_version: ${{ needs.create-github-release-workflow.outputs.LATEST_TAG}}
level: ${{ needs.create-github-release-workflow.outputs.INC_LEVEL}}
preID: rc
- name: Show next sem-version
if: needs.create-github-release-workflow.outputs.LATEST_TAG != ''
run: |
echo "MANUAL_VERSION=${{ steps.set-semver-info.outputs.new_version }}" > "$GITHUB_ENV"
- run: |
echo "Next version: ${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_STEP_SUMMARY"
- name: Create new release
id: create_release
uses: keyfactor/action-create-release@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MANUAL_VERSION: ${{ env.MANUAL_VERSION }}
if: github.event_name == 'pull_request' && needs.create-github-release-workflow.outputs.IS_RELEASE_BRANCH == 'True'
with:
release_name: ${{ env.MANUAL_VERSION }}
body: |
[Changelog](/./CHANGELOG.md)
[Readme](/./README.md)
For the latest README.md updates visit the [Main Page](/../main) for this repository
draft: false
prerelease: ${{ needs.create-github-release-workflow.outputs.IS_PRE_RELEASE == 'True'}}
prerelease_suffix: rc
tag_name: ${{ env.MANUAL_VERSION }}
auto_increment_type: ${{ (needs.create-github-release-workflow.outputs.IS_PRE_RELEASE == 'True') && 'prerelease' || 'patch' }}
tag_schema: semantic
commitish: ${{ github.sha }}