-
Notifications
You must be signed in to change notification settings - Fork 49
169 lines (158 loc) · 6.2 KB
/
codegen-preview.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
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
name: codegen diff preview
# This job will generate a codegen output diff comparing the target base ref with current HEAD ref and push it to S3
# and comment on GitHub PR with a link to the HTML output.
on:
pull_request:
types:
- opened
- reopened
- synchronize
permissions:
id-token: write
contents: read
pull-requests: write
# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
concurrency:
group: ci-codegen-diff-${{ github.ref }}
cancel-in-progress: true
env:
JAVA_VERSION: 17
RUN: ${{ github.run_id }}-${{ github.run_number }}
DIFF2HTML_VERSION: 5.2.5
# Below is the set of services that are generated for codegen preview
# These are carefully selected to exercise every Smithy protocol.
# - @awsJson1_0: dynamodb
# - @awsJson1_1: codebuild
# - @awsQuery: sts
# - @ec2Query: ec2
# - @restJson1: polly
# - @restXml: s3
PREVIEW_SERVICES: +dynamodb,+codebuild,+sts,+ec2,+polly,+s3
HEAD_BRANCH_NAME: __tmp-localonly-head
BASE_BRANCH_NAME: __tmp-localonly-base
jobs:
generate-codegen-diff:
runs-on: ubuntu-latest
name: Generate diff and upload to S3
outputs:
bot-message: ${{ steps.generate-diff.outputs.codegen-diff-msg }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
path: 'aws-sdk-kotlin'
- uses: actions/checkout@v4
with:
repository: 'awslabs/aws-kotlin-repo-tools'
path: 'aws-kotlin-repo-tools'
- uses: actions/checkout@v4
with:
repository: 'smithy-lang/smithy-kotlin'
fetch-depth: 0
path: 'smithy-kotlin'
- uses: actions/checkout@v4
with:
repository: 'smithy-lang/smithy-rs'
path: 'smithy-rs'
sparse-checkout: |
tools/ci-build/difftags
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'corretto'
cache: 'gradle'
- name: Install deps and setup environment
run: |
# store off a copy of head ref of ci.py, otherwise base ref generation will use a different version of this script
CODEGEN_DIFF_REVISIONS=${{ runner.temp }}/codegen-diff-revisions.py
cp $GITHUB_WORKSPACE/aws-sdk-kotlin/.github/scripts/codegen-diff-revisions.py $CODEGEN_DIFF_REVISIONS
echo "CODEGEN_DIFF_REVISIONS=$CODEGEN_DIFF_REVISIONS" >> "$GITHUB_ENV"
echo "REPO_TOOLS=$GITHUB_WORKSPACE/aws-kotlin-repo-tools" >> "$GITHUB_ENV"
echo "SMITHY_KOTLIN_DIR=$GITHUB_WORKSPACE/smithy-kotlin" >> "$GITHUB_ENV"
echo "SDK_DIR=$GITHUB_WORKSPACE/aws-sdk-kotlin" >> "$GITHUB_ENV"
echo "installing smithy-rs diff tooling"
pushd $GITHUB_WORKSPACE/smithy-rs/tools/ci-build/difftags
cargo install --path .
difftags --version
popd
- name: Generate code for head ref
run: |
branch=$(python3 $REPO_TOOLS/scripts/ci.py get-branch $SDK_DIR)
pushd $SMITHY_KOTLIN_DIR
if git ls-remote --quiet --exit-code --heads origin refs/heads/$branch
then
echo "using smithy-kotlin branch $branch for head ref codegen"
else
# in the case of feature branches with tentacles we may or may not have a corresponding base ref in smithy-kotlin
# if we do let's use that, otherwise fallback to main
echo "$branch does not exist in smithy-kotlin, will attempt base ref $GITHUB_BASE_REF"
branch=$GITHUB_BASE_REF
fi
python3 $REPO_TOOLS/scripts/ci.py -v set-branch --branch $branch
popd
pushd $SDK_DIR
git checkout -b $HEAD_BRANCH_NAME
$CODEGEN_DIFF_REVISIONS codegen --bootstrap ${{ env.PREVIEW_SERVICES }}
popd
- name: Generate code for base ref
run: |
branch=$GITHUB_BASE_REF
echo "checkout smithy-kotlin at base ref: $branch"
pushd $SMITHY_KOTLIN_DIR
git switch -f main
python3 $REPO_TOOLS/scripts/ci.py -v set-branch --branch $branch
popd
echo "resetting aws-sdk-kotlin"
pushd $SDK_DIR
git switch -f main
python3 $REPO_TOOLS/scripts/ci.py -v set-branch --branch $branch
git checkout -b $BASE_BRANCH_NAME
$CODEGEN_DIFF_REVISIONS codegen --bootstrap ${{ env.PREVIEW_SERVICES }}
popd
- name: Generate diffs
id: generate-diff
run: |
pushd $SDK_DIR
$CODEGEN_DIFF_REVISIONS \
--head-sha ${{ github.event.pull_request.head.sha }} \
generate-diffs \
--base-sha ${{ github.event.pull_request.base.sha }} \
$BASE_BRANCH_NAME $HEAD_BRANCH_NAME
cat ./tmp-codegen-diff/bot-message
{
echo 'codegen-diff-msg<<DIFF_MSG_EOF'
echo "$(cat ./tmp-codegen-diff/bot-message)"
echo 'DIFF_MSG_EOF'
} >> "$GITHUB_OUTPUT"
echo $GITHUB_OUTPUT
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
aws-region: us-west-2
- name: Upload diff to S3
run: |
SDK_DIR=$GITHUB_WORKSPACE/aws-sdk-kotlin
pushd $SDK_DIR
if [[ -d ./tmp-codegen-diff/${{ github.event.pull_request.base.sha }} ]]; then
aws s3 cp ./tmp-codegen-diff/${{ github.event.pull_request.base.sha }} \
"s3://${{ secrets.CDN_S3_BUCKET_NAME }}/codegen-diff/${{ github.event.pull_request.base.sha }}" --recursive
fi
# TODO - generate doc preview for N services and upload and link as well
post-bot-comment:
name: Post bot comment
runs-on: ubuntu-latest
needs:
- generate-codegen-diff
steps:
- name: Post bot comment
uses: actions/github-script@v5
with:
script: |
await github.rest.issues.createComment({
issue_number: ${{ github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: '${{ needs.generate-codegen-diff.outputs.bot-message }}\n\n'
})