Skip to content

Commit 70fef17

Browse files
authored
Merge pull request #124 from brendandburns/master
Add a github action for generating code.
2 parents 381c412 + 6be8eca commit 70fef17

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

.github/workflows/generate.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Generate
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
kubernetesBranch:
7+
type: string
8+
required: true
9+
description: 'The remote kubernetes release branch to fetch openapi spec. .e.g. "release-1.23"'
10+
genCommit:
11+
type: string
12+
required: true
13+
default: 'master'
14+
description: 'The commit to use for the kubernetes-client/gen repo'
15+
clientVersion:
16+
type: string
17+
required: true
18+
default: '0.3.0'
19+
description: 'Semvar to use for the version number'
20+
21+
22+
jobs:
23+
generate:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout C
27+
uses: actions/checkout@v3
28+
- name: Checkout Gen
29+
run: |
30+
git clone https://github.com/kubernetes-client/gen
31+
pushd gen
32+
git checkout "${{ github.event.inputs.genCommit }}"
33+
- name: Generate Branch Name
34+
run: |
35+
SUFFIX=$(openssl rand -hex 4)
36+
echo "BRANCH=automated-generate-$SUFFIX" >> $GITHUB_ENV
37+
- name: Remove old files
38+
run: |
39+
find kubernetes/model -type f -not -name "int_or_string*" -exec rm -r {} \;
40+
find kubernetes/api -type f -not -name "int_or_string*" -exec rm -r {} \;
41+
find kubernetes/unit-test -type f -not -name "manual*" -exec rm -r {} \;
42+
- name: Generate Openapi
43+
run: |
44+
pushd gen/openapi
45+
cat <<"EOF"> settings
46+
# Kubernetes branch/tag to get the OpenAPI spec from.
47+
export KUBERNETES_BRANCH="${{ github.event.inputs.kubernetesBranch }}"
48+
49+
# client version is not currently used by the code generator.
50+
export CLIENT_VERSION="${{github.event.inputs.clientVersion}}"
51+
52+
# Name of the release package
53+
export PACKAGE_NAME="client"
54+
55+
# OpenAPI-Generator branch/tag to generate the client library
56+
export OPENAPI_GENERATOR_COMMIT="master"
57+
58+
export USERNAME=kubernetes
59+
EOF
60+
bash c.sh ../../kubernetes settings
61+
cp settings ../../settings
62+
popd
63+
rm -rf gen
64+
- name: Update version
65+
run: |
66+
perl -pi -e "s/PROJECT_VERSION_MAJOR \\d/PROJECT_VERSION_MAJOR $(echo ${{ github.event.inputs.clientVersion }} | awk -F. '{print $1}')/" kubernetes/PreTarget.cmake
67+
perl -pi -e "s/PROJECT_VERSION_MINOR \\d/PROJECT_VERSION_MINOR $(echo ${{ github.event.inputs.clientVersion }} | awk -F. '{print $2}')/" kubernetes/PreTarget.cmake
68+
perl -pi -e "s/PROJECT_VERSION_PATCH \\d/PROJECT_VERSION_PATCH $(echo ${{ github.event.inputs.clientVersion }} | awk -F. '{print $3}')/" kubernetes/PreTarget.cmake
69+
- name: Commit and push
70+
run: |
71+
# Commit and push
72+
git config user.email "[email protected]"
73+
git config user.name "Kubernetes Prow Robot"
74+
git checkout -b "$BRANCH"
75+
git add .
76+
git commit -s -m 'Automated openapi generation from ${{ github.event.inputs.kubernetesBranch }}'
77+
git push origin "$BRANCH"
78+
- name: Pull Request
79+
uses: repo-sync/pull-request@v2
80+
with:
81+
source_branch: ${{ env.BRANCH }}
82+
destination_branch: ${{ github.ref_name }}
83+
github_token: ${{ secrets.GITHUB_TOKEN }}
84+
pr_title: "Automated Generate from openapi ${{ github.event.inputs.kubernetesBranch }}"

0 commit comments

Comments
 (0)