-
Notifications
You must be signed in to change notification settings - Fork 17
148 lines (119 loc) · 4.25 KB
/
prod-deploy.yaml
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
name: prod-deploy
on:
pull_request:
types: [ closed ]
jobs:
prepare-release:
name: Release to Prod
runs-on: ubuntu-latest
outputs:
version: ${{ steps.vars.outputs.version }}
python_version: ${{ steps.python.outputs.python_version }}
# If merged & pr was tagged release & from a release branch
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.merged == true && (github.event.pull_request.head.ref == 'release' || github.event.pull_request.head.ref == 'hotfix')
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Python version
id: python
shell: bash
run: echo ::set-output name=python_version::$(make python-version)
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ steps.python.outputs.python_version }}
- name: Install pipenv
run: make install
- id: cache-pipenv
uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv-
${{ runner.os }}-
- name: Install dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: make init
- name: Set variables
id: vars
run: echo ::set-output name=version::$(make version)
build-deploy:
name: Build & Deploy to PROD
runs-on: ubuntu-latest
needs: prepare-release
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
ref: ${{ needs.prepare-release.outputs.branch }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ needs.prepare-release.outputs.python_version }}
- name: Install pipenv
run: make install
- id: cache-pipenv
uses: actions/cache@v1
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pipenv-
${{ runner.os }}-
- name: Install dependencies
if: steps.cache-pipenv.outputs.cache-hit != 'true'
run: make init
- name: Package code
run: make package
- name: Upload package
uses: actions/upload-artifact@v2
with:
name: egg-${{ steps.vars.outputs.version }}
path: dist/
- name: Deploy package to prod
run: echo "DEPLOY v${{ steps.vars.outputs.version }} TO PROD"
success:
needs: [ prepare-release, build-deploy ]
name: Notify success
runs-on: ubuntu-latest
steps:
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.prepare-release.outputs.version }}
release_name: Release ${{ needs.prepare-release.outputs.version }}
draft: false
prerelease: false
- name: Delete current release/hotfix branch
uses: dawidd6/action-delete-branch@v3
continue-on-error: true
with:
github_token: ${{github.token}}
branches: ${{ github.event.pull_request.head.ref}}
abandon-release:
name: Abandon Release to Prod
runs-on: ubuntu-latest
# If PR was closed, but not merged
if: contains(github.event.pull_request.labels.*.name, 'release') && github.event.pull_request.merged == false && github.event.pull_request.head.ref == 'release'
steps:
- name: Check out repository code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Delete tag
shell: bash
run: |
# TODO fix tag deletion => sometimes the tag is on another commit in the branch
TAG=$(git describe --exact-match ${{ github.event.pull_request.head.sha }})
echo $TAG
git tag -d $TAG
git push --tags origin :refs/tags/$TAG