Skip to content

Commit 33c4f01

Browse files
committed
fix: cd
1 parent 3b9d028 commit 33c4f01

2 files changed

Lines changed: 181 additions & 254 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 181 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,224 @@
11
name: CD
22
on:
3-
push:
4-
branches:
5-
- main
6-
# When Pull Request is merged
7-
# pull_request_target:
8-
# types: [closed]
3+
pull_request:
4+
types: [closed]
95

106
jobs:
11-
GetVersion:
7+
Pre-Check:
8+
if: |
9+
github.event.pull_request.merged &&
10+
endsWith(github.event.pull_request.title, '/workflows/cd') &&
11+
github.event.pull_request.user.login != 'polywrap-build-bot'
1212
runs-on: ubuntu-latest
13-
timeout-minutes: 60
14-
outputs:
15-
version: ${{ env.RELEASE_VERSION }}
16-
# if: |
17-
# github.event.pull_request.user.login == 'polywrap-build-bot' &&
18-
# github.event.pull_request.merged == true
1913
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v2
22-
# - name: Halt release if CI failed
23-
# run: exit 1
24-
# if: ${{ github.event.workflow_run.conclusion == 'failure' }}
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
ref: ${{github.event.pull_request.base.ref}}
18+
19+
- name: Pull-Request Creator Is Publisher?
20+
run: |
21+
exists=$(echo $(grep -Fxcs ${CREATOR} .github/PUBLISHERS))
22+
if [ "$exists" == "1" ] ; then
23+
echo IS_PUBLISHER=true >> $GITHUB_ENV
24+
else
25+
echo IS_PUBLISHER=false >> $GITHUB_ENV
26+
fi
27+
env:
28+
CREATOR: ${{github.event.pull_request.user.login}}
29+
30+
- name: Creator Is Not Publisher...
31+
if: env.IS_PUBLISHER == 'false'
32+
uses: actions/github-script@0.8.0
33+
with:
34+
github-token: ${{secrets.GITHUB_TOKEN}}
35+
script: |
36+
github.issues.createComment({
37+
issue_number: context.issue.number,
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
body: '${{github.event.pull_request.user.login}} is not a PUBLISHER. Please see the .github/PUBLISHERS file...'
41+
})
42+
2543
- name: Read VERSION into env.RELEASE_VERSION
2644
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
27-
- name: Check if tag Exists
45+
46+
- name: Tag Exists?
2847
id: tag_check
2948
shell: bash -ex {0}
3049
run: |
3150
GET_API_URL="https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}"
3251
http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \
3352
-H "Authorization: token ${GITHUB_TOKEN}")
3453
if [ "$http_status_code" -ne "404" ] ; then
35-
exit 1
54+
echo TAG_EXISTS=true >> $GITHUB_ENV
55+
else
56+
echo TAG_EXISTS=false >> $GITHUB_ENV
3657
fi
3758
env:
3859
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3960

40-
Github-release:
41-
name: Create Release
42-
runs-on: ubuntu-latest
43-
needs:
44-
- GetVersion
45-
steps:
46-
- name: Checkout code
47-
uses: actions/checkout@v2
48-
- name: print version with needs
49-
run: echo ${{ needs.GetVersion.outputs.version }}
50-
- id: changelog
51-
name: "Generate release changelog"
52-
uses: heinrichreimer/github-changelog-generator-action@v2.3
53-
with:
54-
unreleasedOnly: true
55-
unreleasedLabel: ${{ needs.GetVersion.outputs.version }}
56-
token: ${{ secrets.GITHUB_TOKEN }}
57-
continue-on-error: true
58-
- name: Create Release
59-
id: create_release
60-
uses: actions/create-release@v1
61-
env:
62-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
- name: Release Already Exists...
62+
if: env.TAG_EXISTS == 'true'
63+
uses: actions/github-script@0.8.0
6364
with:
64-
tag_name: ${{ needs.GetVersion.outputs.version }}
65-
release_name: Release ${{ needs.GetVersion.outputs.version }}
66-
body: ${{ steps.changelog.outputs.changelog }}
67-
draft: true
68-
prerelease: false
65+
github-token: ${{secrets.GITHUB_TOKEN}}
66+
script: |
67+
github.issues.createComment({
68+
issue_number: context.issue.number,
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
body: '[Release Already Exists](https://api.github.com/repos/${{github.repository}}/git/ref/tags/${{env.RELEASE_VERSION}}) (`${{env.RELEASE_VERSION}}`)'
72+
})
6973
70-
Dev-PR:
71-
needs:
72-
- GetVersion
74+
- name: Fail If Conditions Aren't Met...
75+
if: |
76+
env.IS_PUBLISHER != 'true' ||
77+
env.TAG_EXISTS != 'false'
78+
run: exit 1
79+
80+
CD:
81+
needs: Pre-Check
7382
runs-on: ubuntu-latest
7483
steps:
7584
- name: Checkout
7685
uses: actions/checkout@v3
7786
with:
78-
ref: dev
79-
fetch-depth: 0
87+
ref: ${{github.event.pull_request.base.ref}}
88+
89+
- name: Set env.BUILD_BOT to Build Bot's Username
90+
run: echo BUILD_BOT=polywrap-build-bot >> $GITHUB_ENV
91+
92+
- name: Read VERSION into env.RELEASE_VERSION
93+
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
94+
95+
- name: Building CD PR...
96+
uses: actions/github-script@0.8.0
97+
with:
98+
github-token: ${{secrets.GITHUB_TOKEN}}
99+
script: |
100+
github.issues.createComment({
101+
issue_number: context.issue.number,
102+
owner: context.repo.owner,
103+
repo: context.repo.repo,
104+
body: '[Building CD PR](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) (`${{env.RELEASE_VERSION}}`)'
105+
})
106+
107+
- name: Set up Python 3.10
108+
uses: actions/setup-python@v4
109+
with:
110+
python-version: "3.10"
111+
112+
- name: Install poetry
113+
run: curl -sSL https://install.python-poetry.org | python3 -
114+
115+
- name: Install tomlkit
116+
run: pip3 install tomlkit
80117

81118
- name: Set Git Identity
82119
run: |
83120
git config --global user.name '${{env.BUILD_BOT}}'
84121
git config --global user.email '${{env.BUILD_BOT}}@users.noreply.github.com'
85-
env:
86-
GITHUB_TOKEN: ${{ secrets.POLYWRAP_BUILD_BOT_PAT }}
87-
88-
- name: Merge main into dev
89-
run: git merge origin/main
90-
91-
- name: set env.RELEASE_FORKS to Release Forks' Organization
92-
run: echo RELEASE_FORKS=polywrap-release-forks >> $GITHUB_ENV
93122
94-
- name: Set env.BUILD_BOT to Build Bot's Username
95-
run: echo BUILD_BOT=polywrap-build-bot >> $GITHUB_ENV
123+
- name: Publish to PyPI
124+
run: python3 scripts/publish_packages.py
125+
env:
126+
POLYWRAP_BUILD_BOT_PYPI_PAT: ${{ secrets.POLYWRAP_BUILD_BOT_PYPI_PAT }}
96127

97-
- name: Read VERSION into env.RELEASE_VERSION
98-
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
128+
- name: Commit Changes
129+
run: |
130+
git add .
131+
git commit -m "chore: patch version to ${{env.RELEASE_VERSION}}"
99132
100-
# - name: Set up Python 3.10
101-
# uses: actions/setup-python@v4
102-
# with:
103-
# python-version: "3.10"
133+
- name: Create Pull Request from dev to main
134+
id: cpr-cd
135+
uses: peter-evans/create-pull-request@v3
136+
with:
137+
branch: cd/${{env.RELEASE_VERSION}}
138+
base: ${{github.event.pull_request.base.ref}}
139+
committer: GitHub <noreply@github.com>
140+
author: ${{env.BUILD_BOT}} <${{env.BUILD_BOT}}@users.noreply.github.com>
141+
commit-message: "chore: CD ${{env.RELEASE_VERSION}}"
142+
title: 'Python client CD (${{env.RELEASE_VERSION}})'
143+
body: |
144+
## Python client CD (${{env.RELEASE_VERSION}})
104145
105-
# - name: Install poetry
106-
# run: curl -sSL https://install.python-poetry.org | python3 -
146+
- name: Release PR Created...
147+
uses: actions/github-script@0.8.0
148+
with:
149+
github-token: ${{secrets.GITHUB_TOKEN}}
150+
script: |
151+
github.issues.createComment({
152+
issue_number: context.issue.number,
153+
owner: context.repo.owner,
154+
repo: context.repo.repo,
155+
body: '**[Release PR Created](https://github.com/${{github.repository}}/pull/${{ steps.cpr-cd.outputs.pull-request-number }}) (`${{env.RELEASE_VERSION}}`)**'
156+
})
107157
108-
# - name: Install tomlkit
109-
# run: pip3 install tomlkit
158+
- name: Building POST CD PR...
159+
uses: actions/github-script@0.8.0
160+
with:
161+
github-token: ${{secrets.GITHUB_TOKEN}}
162+
script: |
163+
github.issues.createComment({
164+
issue_number: context.issue.number,
165+
owner: context.repo.owner,
166+
repo: context.repo.repo,
167+
body: '[Building POST CD PR](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) (`${{env.RELEASE_VERSION}}`)'
168+
})
110169
111-
# - name: Link Packages in dev branch
112-
# run: python3 scripts/link_packages.py
170+
- name: Link Packages in dev branch
171+
run: python3 scripts/link_packages.py
113172

114-
- name: Create Pull Request
115-
id: cpr
173+
- name: Create Pull Request from main to dev
174+
id: cpr-post-cd
116175
uses: peter-evans/create-pull-request@v3
117176
with:
118-
token: ${{ secrets.POLYWRAP_BUILD_BOT_PAT }}
119-
push-to-fork: ${{env.RELEASE_FORKS}}/${{github.event.pull_request.base.repo.name}}
120-
# branch: post-release/origin-${{env.RELEASE_VERSION}}
121-
# base: origin/dev
177+
branch: cd/${{env.RELEASE_VERSION}}
178+
base: ${{github.event.pull_request.compare.ref}}
122179
committer: GitHub <noreply@github.com>
123180
author: ${{env.BUILD_BOT}} <${{env.BUILD_BOT}}@users.noreply.github.com>
124-
commit-message: "DEV ${{env.RELEASE_VERSION}}"
125-
title: 'Link packages in dev after (${{env.RELEASE_VERSION}})'
181+
commit-message: "chore: POST CD ${{env.RELEASE_VERSION}}"
182+
title: 'Python client POST CD (${{env.RELEASE_VERSION}})'
126183
body: |
127-
## Link packages in dev after (${{env.RELEASE_VERSION}})
184+
## Python client POST CD (${{env.RELEASE_VERSION}})
185+
186+
- name: POST CD PR Created...
187+
uses: actions/github-script@0.8.0
188+
with:
189+
github-token: ${{secrets.GITHUB_TOKEN}}
190+
script: |
191+
github.issues.createComment({
192+
issue_number: context.issue.number,
193+
owner: context.repo.owner,
194+
repo: context.repo.repo,
195+
body: '**[POST CD PR Created](https://github.com/${{github.repository}}/pull/${{ steps.cpr-post-cd.outputs.pull-request-number }}) (`${{env.RELEASE_VERSION}}`)**'
196+
})
197+
198+
Github-release:
199+
name: Create Release
200+
runs-on: ubuntu-latest
201+
steps:
202+
- name: Checkout code
203+
uses: actions/checkout@v3
204+
- name: Read VERSION into env.RELEASE_VERSION
205+
run: echo RELEASE_VERSION=$(cat VERSION) >> $GITHUB_ENV
206+
- id: changelog
207+
name: "Generate release changelog"
208+
uses: heinrichreimer/github-changelog-generator-action@v2.3
209+
with:
210+
unreleasedOnly: true
211+
unreleasedLabel: ${{ env.RELEASE_VERSION }}
212+
token: ${{ secrets.GITHUB_TOKEN }}
213+
continue-on-error: true
214+
- name: Create Release
215+
id: create_release
216+
uses: actions/create-release@v1
217+
env:
218+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
219+
with:
220+
tag_name: ${{ env.RELEASE_VERSION }}
221+
release_name: Release ${{ env.RELEASE_VERSION }}
222+
body: ${{ steps.changelog.outputs.changelog }}
223+
draft: true
224+
prerelease: true

0 commit comments

Comments
 (0)