forked from rollkit/rollkit
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (122 loc) · 4.45 KB
/
ci_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
name: CI and Release
on:
push:
branches:
- main
# Trigger on version tags
tags:
- 'v[0-9]+\.[0-9]+\.[0-9]+'
- 'v[0-9]+\.[0-9]+\.[0-9]+-rc(?:[0-9]+|\.[0-9]+)'
pull_request:
merge_group:
workflow_dispatch:
# Inputs the workflow accepts.
inputs:
version:
# Friendly description to be shown in the UI instead of 'name'
description: "Semver type of new version (major / minor / patch)"
# Input has to be provided for the workflow to run
required: true
type: choice
options:
- patch
- minor
- major
jobs:
setup:
runs-on: ubuntu-latest
env:
# use consistent go version throughout pipeline here
GO_VERSION: "1.21"
outputs:
go-version: ${{ steps.set-vars.outputs.go-version }}
steps:
- name: Set go version
id: set-vars
run: echo "go-version=${{env.GO_VERSION}}" >> "$GITHUB_OUTPUT"
lint:
needs: [setup]
uses: ./.github/workflows/lint.yml
with:
go-version: ${{ needs.setup.outputs.go-version }}
test:
needs: [setup]
uses: ./.github/workflows/test.yml
with:
go-version: ${{ needs.setup.outputs.go-version }}
proto:
uses: ./.github/workflows/proto.yml
# get_merged_pr_labels uses the listPullRequestsAssociatedWithCommit API
# endpoint to get the PR information for the commit during a push event. Once
# the PR information is received, we check to see if the create-release label
# was added to the pr.
get_merged_pr_labels:
runs-on: ubuntu-latest
outputs:
has_release_label: ${{ steps.set-outputs.outputs.has_release_label }}
steps:
# We only want to run this step on a push event, otherwise this will error
# out as the result is null. We have the if condition here as to not block
# steps that rely on this step and others if this step is skipped.
- name: Query listPullRequestsAssociatedWithCommit for the PR information
if: ${{ github.event_name == 'push' }}
uses: actions/github-script@v7
id: get_pr_data
with:
script: |
const prData = await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
});
const pr = prData.data[0];
const prLabels = pr ? pr.labels.map(label => label.name) : [];
const hasReleaseLabel = prLabels.includes('create-release');
return { hasReleaseLabel };
# Only run if the result is not null. We add this check so that the CI
# does not show a failure when the previous step is skipped.
- name: Set the outputs
if: steps.get_pr_data.outputs.result != null
id: set-outputs
run: echo "has_release_label=${{ fromJSON(steps.get_pr_data.outputs.result).hasReleaseLabel }}" >> "$GITHUB_OUTPUT"
# branch_name trims ref/heads/ from github.ref to access a clean branch name
branch_name:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.trim_ref.outputs.branch }}
steps:
- name: Trim branch name
id: trim_ref
run: |
echo "branch=$(${${{ github.ref }}:11})" >> $GITHUB_OUTPUT
# Make a release if this is a manually trigger job, i.e. workflow_dispatch
release-dispatch:
needs: [lint, test, proto, branch_name]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' }}
permissions: "write-all"
steps:
- uses: actions/checkout@v4
- name: Version Release
uses: rollkit/.github/.github/actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
version-bump: ${{inputs.version}}
release-branch: ${{needs.branch_name.outputs.branch}}
# Make a release if there was a merged pr with the create-release label
release-merge:
needs: [lint, test, proto, get_merged_pr_labels, branch_name]
runs-on: ubuntu-latest
if: |
(github.event_name == 'push' &&
contains(github.ref, 'refs/heads/main') &&
needs.get_merged_pr_labels.outputs.has_release_label)
permissions: "write-all"
steps:
- uses: actions/checkout@v4
- name: Version Release
uses: rollkit/.github/.github/actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
version-bump: "patch"
release-branch: ${{needs.branch_name.outputs.branch}}