-
Notifications
You must be signed in to change notification settings - Fork 60
126 lines (117 loc) · 3.93 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
name: Release
on:
workflow_dispatch:
inputs:
releaseType:
type: choice
options:
- minor
- patch
default: minor
required: true
description: '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: Check user permission
uses: actions-cool/check-user-permission@v2.2.0
id: check
with:
require: 'write'
outputs:
hasWritePermission: ${{ steps.check.outputs.require-result }}
publish-tag:
name: Publish tag
needs: check-permission
if: contains(needs.check-permission.outputs.hasWritePermission, 'true')
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout prebid cache
uses: actions/checkout@v3
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 == "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 cache
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build image
run: |
docker build --build-arg DEPLOY_VERSION=${{ needs.publish-tag.outputs.releaseTag }} -t docker.io/prebid/prebid-cache:${{ needs.publish-tag.outputs.releaseTag }} .
- name: Login to docker Hub
if: contains(inputs.debug, 'false')
uses: docker/login-action@v2.1.0
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Publish to docker Hub
run: |
docker push docker.io/prebid/prebid-cache:${{ 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 cache
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create & publish release
uses: release-drafter/release-drafter@v5.22.0
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 }}