-
Notifications
You must be signed in to change notification settings - Fork 20
111 lines (94 loc) · 3.98 KB
/
python-client-gen.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
name: Python Client Generation
on:
workflow_dispatch:
inputs:
openapi_short_sha:
description: "The short commit sha that triggered the workflow"
required: true
type: string
env:
NEW_BRANCH: openapi-${{ github.event.inputs.openapi_short_sha }}/clientgen
jobs:
Generate-Python-Client:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: OpenAPI Changelist
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
run: |
current_sha=$(cat DO_OPENAPI_COMMIT_SHA.txt)
echo "current_sha=$current_sha" >> $GITHUB_ENV
target_sha=${{ github.event.inputs.openapi_short_sha }}
scripts/openapi_changelist.sh $current_sha $target_sha > changelist.md
- name: Removes all generated code
run: make clean
- name: Download spec file and Update DO_OPENAPI_COMMIT_SHA.txt
run: |
curl --fail https://api-engineering.nyc3.digitaloceanspaces.com/spec-ci/DigitalOcean-public-${{ github.event.inputs.openapi_short_sha }}.v2.yaml -o DigitalOcean-public.v2.yaml
echo ${{ github.event.inputs.openapi_short_sha }} > DO_OPENAPI_COMMIT_SHA.txt
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- uses: actions/upload-artifact@v2
with:
name: DigitalOcean-public.v2
path: ./DigitalOcean-public.v2.yaml
- name: Checkout new Branch
run: git checkout -b ${{ env.NEW_BRANCH }}
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.6.1
virtualenvs-path: .venv
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: false
- name: Generate Python client
run: make generate
- name: Generate Python client documentation
run: make generate-docs
- name: Add and commit changes
id: add-commit-changes
continue-on-error: true
run: |
git config --global user.email "[email protected]"
git config --global user.name "API Engineering"
git add .
git commit -m "[bot] Updated client based on ${{ env.NEW_BRANCH }}"
git push --set-upstream origin ${{ env.NEW_BRANCH }}
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
- name: Check if branch existed
# If steps.create-pr was anything but successful, it's possible that
# the branch was created in previous pipeline runs so it should be manually deleted.
if: steps.add-commit-changes.outcome != 'success'
run: |
echo "Add and commit changes step failed. It's possible the branch ${{ env.NEW_BRANCH }} already existed. Please delete the branch and re-run the pipeline."
exit 1
- name: Set pr_title outputs
id: pr_title_var
run: echo "PR_TITLE=$(gh pr list --search "${{ github.event.inputs.openapi_short_sha }}" --json title --jq '.[0].title' --repo digitalocean/openapi --state merged)" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check pr_title outputs
run: echo ${{ steps.pr_title_var.outputs.PR_TITLE }}
- name: Create Pull Request
id: create-pr
if: steps.add-commit-changes.outcome == 'success'
run: |
export CURRENT=$(cat DO_OPENAPI_COMMIT_SHA.txt)
export TARGET=${{ github.event.inputs.openapi_short_sha }}
export TITLE="${{ steps.pr_title_var.outputs.PR_TITLE }}"
envsubst < scripts/pr_body.md_tmpl > pr_body.md
cat changelist.md >> pr_body.md
echo "PR BODY:"
cat pr_body.md
gh pr create \
--title "[bot] $TITLE: Re-Generated From digitalocean/openapi@$TARGET" \
--body-file pr_body.md \
--head "${{ env.NEW_BRANCH }}" \
-r digitalocean/api-cli
env:
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}