-
Notifications
You must be signed in to change notification settings - Fork 6
178 lines (157 loc) · 6.1 KB
/
cd.yaml
File metadata and controls
178 lines (157 loc) · 6.1 KB
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
176
177
178
name: CD
on:
pull_request:
types: [closed]
branches: [main]
jobs:
Pre-Check:
if: |
github.event.pull_request.merged &&
endsWith(github.event.pull_request.title, '/workflows/cd') &&
github.event.pull_request.user.login != 'polywrap-build-bot'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.base.ref}}
- name: Pull-Request Creator Is Publisher?
run: |
exists=$(echo $(grep -Fxcs ${CREATOR} .github/PUBLISHERS))
if [ "$exists" == "1" ] ; then
echo IS_PUBLISHER=true >> $GITHUB_ENV
else
echo IS_PUBLISHER=false >> $GITHUB_ENV
fi
env:
CREATOR: ${{github.event.pull_request.user.login}}
- name: Creator Is Not Publisher...
if: env.IS_PUBLISHER == 'false'
uses: actions/github-script@0.8.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '${{github.event.pull_request.user.login}} is not a PUBLISHER. Please see the .github/PUBLISHERS file...'
})
- name: Read VERSION into env.RELEASE_VERSION
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
- name: Tag Exists?
id: tag_check
shell: bash -ex {0}
run: |
GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}"
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
-H "Authorization: token ${GITHUB_TOKEN}")
if [ "$http_status_code" -ne "404" ] ; then
echo TAG_EXISTS=true >> $GITHUB_ENV
else
echo TAG_EXISTS=false >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release Already Exists...
if: env.TAG_EXISTS == 'true'
uses: actions/github-script@0.8.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '[Release Already Exists](https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}) (`${{env.RELEASE_VERSION}}`)'
})
- name: Fail If Conditions Aren't Met...
if: |
env.IS_PUBLISHER != 'true' ||
env.TAG_EXISTS != 'false'
run: exit 1
CD:
needs: Pre-Check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.base.ref}}
- name: Set env.BUILD_BOT to Build Bot's Username
run: echo BUILD_BOT=polywrap-build-bot >> $GITHUB_ENV
- name: Read VERSION into env.RELEASE_VERSION
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
- name: Building CD PR...
uses: actions/github-script@0.8.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '[Building CD PR](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) (`${{env.RELEASE_VERSION}}`)'
})
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Setup Node.js
uses: actions/setup-node@master
with:
node-version: 'v18.16.0'
- name: Install poetry
run: curl -sSL https://install.python-poetry.org | python3 -
- name: Install tomlkit
run: pip3 install tomlkit
- name: Set Git Identity
run: |
git config --global user.name '${{env.BUILD_BOT}}'
git config --global user.email '${{env.BUILD_BOT}}@users.noreply.github.com'
- name: Publish to PyPI
run: python3 scripts/publish_packages.py
env:
POLYWRAP_BUILD_BOT_PYPI_PAT: ${{ secrets.POLYWRAP_BUILD_BOT_PYPI_PAT }}
- name: Create Pull Request from dev to main
id: cpr-cd
uses: peter-evans/create-pull-request@v3
with:
branch: cd/${{env.RELEASE_VERSION}}
delete-branch: true
committer: GitHub <noreply@github.com>
author: ${{env.BUILD_BOT}} <${{env.BUILD_BOT}}@users.noreply.github.com>
commit-message: "chore: patch version to ${{env.RELEASE_VERSION}}"
title: 'Python client CD (${{env.RELEASE_VERSION}})'
body: |
## Python client CD (${{env.RELEASE_VERSION}})
- name: CD PR Created...
uses: actions/github-script@0.8.0
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '**[Release PR Created](https://github.com/${{github.repository}}/pull/${{ steps.cpr-cd.outputs.pull-request-number }}) (`${{env.RELEASE_VERSION}}`)**'
})
- id: changelog
name: "Generate release changelog"
uses: heinrichreimer/github-changelog-generator-action@v2.3
with:
unreleasedOnly: true
unreleasedLabel: ${{ env.RELEASE_VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
body: ${{ steps.changelog.outputs.changelog }}
draft: true
prerelease: true