-
Notifications
You must be signed in to change notification settings - Fork 744
161 lines (151 loc) · 5.3 KB
/
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
name: Release
on:
workflow_dispatch:
inputs:
releaseType:
type: choice
options:
- major
- minor
- patch
default: minor
required: true
description: 'major: vX.0.0, minor: v0.X.0, patch: v0.0.X'
debug:
type: boolean
default: true
description: 'executes the workflow in debug mode (skip the publishing tag, docker image and release steps)'
jobs:
check-permission:
name: Check permission
if: contains(github.ref, 'refs/heads/master')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.repository }}
ref: master
- name: Check user permission
uses: actions/github-script@v7
id: check
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const utils = require('./.github/workflows/helpers/pull-request-utils.js')
const helper = utils.userHelper({github, context, user: '${{ github.actor }}'})
const hasPermission = await helper.hasWritePermissions()
return hasPermission
outputs:
hasWritePermission: ${{ steps.check.outputs.result }}
build-master:
name: Build master
needs: check-permission
if: contains(needs.check-permission.outputs.hasWritePermission, 'true')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
repository: ${{ github.repository }}
ref: master
- name: Build and validate
run: |
./validate.sh
publish-tag:
name: Publish tag
needs: build-master
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Prebid Server
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create & publish tag
id: release
run: |
currentTag=$(git describe --abbrev=0 --tags)
echo "Current release tag ${currentTag}"
echo ${currentTag} | grep -q "^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$"
if [ $? -ne 0 ]; then
echo "Current tag format won't let us compute the new tag name. Required format v[0-9]\+\.[0-9]\+\.[0-9]\+"
exit 1
fi
if [[ "${currentTag:0:1}" != "v" ]]; then
currentTag="v${currentTag}"
fi
nextTag=''
releaseType=${{ inputs.releaseType }}
if [ $releaseType == "major" ]; then
# PBS-GO skipped the v1.0.0 major release - https://github.com/prebid/prebid-server/issues/3068
# If the current tag is v0.x.x, the script sets the next release tag to v2.0.0
# Otherwise, the script increments the major version by 1 and sets the minor and patch versions to zero
# For example, v2.x.x will be incremented to v3.0.0
major=$(echo "${currentTag}" | awk -F. '{gsub(/^v/, "", $1); if($1 == 0) $1=2; else $1+=1; print $1}')
nextTag="v${major}.0.0"
elif [ $releaseType == "minor" ]; then
# Increment minor version and reset patch version
nextTag=$(echo "${currentTag}" | awk -F. '{OFS="."; $2+=1; $3=0; print $0}')
else
# Increment patch version
nextTag=$(echo "${currentTag}" | awk -F. '{OFS="."; $3+=1; print $0}')
fi
if [ ${{ inputs.debug }} == 'true' ]; then
echo "running workflow in debug mode, next ${releaseType} tag: ${nextTag}"
else
git tag $nextTag
git push origin $nextTag
echo "tag=${nextTag}" >> $GITHUB_OUTPUT
fi
outputs:
releaseTag: ${{ steps.release.outputs.tag }}
publish-docker-image:
name: Publish docker image
needs: publish-tag
if: contains(inputs.debug, 'false')
runs-on: ubuntu-latest
steps:
- name: Checkout Prebid Server
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build image
run: |
docker build -t docker.io/prebid/prebid-server:${{ needs.publish-tag.outputs.releaseTag }} .
- name: Login to docker Hub
if: contains(inputs.debug, 'false')
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Publish to docker Hub
run: |
docker push docker.io/prebid/prebid-server:${{ needs.publish-tag.outputs.releaseTag }}
publish-release:
name: Publish release
needs: [publish-tag, publish-docker-image]
if: contains(inputs.debug, 'false')
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Prebid Server
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create & publish release
uses: release-drafter/[email protected]
with:
name: ${{ needs.publish-tag.outputs.releaseTag }}
tag: ${{ needs.publish-tag.outputs.releaseTag }}
version: ${{ needs.publish-tag.outputs.releaseTag }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}