|
| 1 | +name: codegen diff preview |
| 2 | +# This job will generate a branch containing exclusively codegen output and push it to GitHub |
| 3 | +# once the branch is deployed, it will comment on GitHub with a link where you can see the generated diff. |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + # this is a load-bearing branch filter: if this isn't here, you may |
| 8 | + # end up generating diffs for __generated-* branches which would lead to infinite recursion... |
| 9 | + - main |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - reopened |
| 14 | + - closed |
| 15 | + - synchronize |
| 16 | +env: |
| 17 | + JAVA_VERSION: 11 |
| 18 | + BUILDER_VERSION: v0.8.22 |
| 19 | + BUILDER_SOURCE: releases |
| 20 | + BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net |
| 21 | + PACKAGE_NAME: aws-sdk-kotlin |
| 22 | + RUN: ${{ github.run_id }}-${{ github.run_number }} |
| 23 | + # Below is the set of services that are generated for codegen preview |
| 24 | + # These are carefully selected to exercise every Smithy protocol. |
| 25 | + # - @awsJson1_0: dynamodb |
| 26 | + # - @awsJson1_1: config |
| 27 | + # - @awsQuery: sts |
| 28 | + # - @ec2Query: ec2 |
| 29 | + # - @restJson1: polly |
| 30 | + # - @restXml: s3 |
| 31 | + PREVIEW_SERVICES: +dynamodb,+config,+sts,+ec2,+polly,+s3 |
| 32 | + |
| 33 | +jobs: |
| 34 | + cleanup-branch: |
| 35 | + if: ${{ github.event.action == 'closed' }} |
| 36 | + runs-on: ubuntu-latest |
| 37 | + name: cleanup generated code branch |
| 38 | + steps: |
| 39 | + - name: gen branch output |
| 40 | + run: echo "::set-output name=branchname::${GITHUB_HEAD_REF##*/}" |
| 41 | + id: branch_output |
| 42 | + - uses: actions/github-script@v5 |
| 43 | + with: |
| 44 | + script: | |
| 45 | + console.log("deleting the generated code branch"); |
| 46 | + await github.rest.git.deleteRef({ |
| 47 | + owner: context.repo.owner, |
| 48 | + repo: context.repo.repo, |
| 49 | + ref: "heads/__generated-${{ steps.branch_output.outputs.branchname }}" |
| 50 | + }) |
| 51 | +
|
| 52 | + push-generated-code: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + name: Push generated code to a branch |
| 55 | + if: ${{ github.event.action != 'closed' }} |
| 56 | + steps: |
| 57 | + # this is not technically necessary because of the branch filter above, but better to check |
| 58 | + # twice than have an infinitely recursing PR job |
| 59 | + - name: Assert we aren't already on a generated branch |
| 60 | + run: | |
| 61 | + [[ ${GITHUB_HEAD_REF:-$GITHUB_REF} != "*__generated*" ]] |
| 62 | + - uses: actions/checkout@v2 |
| 63 | + - uses: actions/cache@v2 |
| 64 | + name: Gradle Cache |
| 65 | + with: |
| 66 | + path: | |
| 67 | + ~/.gradle/caches |
| 68 | + ~/.gradle/wrapper |
| 69 | + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} |
| 70 | + restore-keys: | |
| 71 | + ${{ runner.os }}-gradle- |
| 72 | + - name: Set up JDK |
| 73 | + uses: actions/setup-java@v1 |
| 74 | + with: |
| 75 | + java-version: ${{ env.JAVA_VERSION }} |
| 76 | + - name: download-deps |
| 77 | + # abuse crt builder to download and build upstream dependencies like smithy-kotlin |
| 78 | + run: | |
| 79 | + python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')" |
| 80 | + chmod a+x builder.pyz |
| 81 | + ./builder.pyz build -p ${{ env.PACKAGE_NAME }} --variant codegen-preview |
| 82 | + - name: mk-generated |
| 83 | + run: | |
| 84 | + echo "aws.services=${{ env.PREVIEW_SERVICES }}" >> local.properties |
| 85 | + .github/scripts/mk-generated.sh |
| 86 | + - name: push generated branch |
| 87 | + run: | |
| 88 | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} |
| 89 | + git push -f origin "$(git rev-parse --abbrev-ref HEAD)" |
| 90 | + - name: finalize |
| 91 | + run: echo "generated output pushed to $(git rev-parse --abbrev-ref HEAD)" |
| 92 | + - name: gen branch output |
| 93 | + run: echo "::set-output name=branchname::$(git rev-parse --abbrev-ref HEAD)" |
| 94 | + id: branch_output |
| 95 | + - uses: actions/github-script@v5 |
| 96 | + # NOTE: if comments on each commit become bothersome, add a check that github.event.pull_request.action == "opened" |
| 97 | + if: ${{ github.head_ref != null }} |
| 98 | + with: |
| 99 | + script: | |
| 100 | + await github.rest.issues.createComment({ |
| 101 | + issue_number: context.issue.number, |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + body: `A new generated diff is ready to view: https://github.com/${context.repo.owner}/${context.repo.repo}/compare/__generated-main...${{ steps.branch_output.outputs.branchname }}` |
| 105 | + }) |
0 commit comments