Skip to content

Commit cd19979

Browse files
authored
chore: Adopt SmithyDafnyMakefile.mk, fix nightly build (#638)
Replaces nearly all of the `SharedMakefile.mk` with the common `smithy-dafny/SmithyDafnyMakefile.mk` makefile, just retaining configuration variables specific to this repo (such as the path to the `smithy-dafny` submodule). Uses the new features in that makefile and `smithy-dafny` itself to make the projects forwards-compatible with the latest Dafny nightly prerelease, and hence will fix the nightly build once merged - [see here for a manual run](https://github.com/aws/aws-encryption-sdk-dafny/actions/runs/8240077703/job/22534705434). Highlights of the changes: * Apply the same workflow changes as aws/aws-cryptographic-material-providers-library#195 to use `smithy-dafny` to regenerate code, either to check that the output matches what's checked in (in a new separate codegen workflow) or to be compatible with newer versions of Dafny in the nightly build (in existing workflows). * In this case we also have to locally update the MPL submodule to the latest, so that we can pick up the forwards-compatible changes to that repo, and regenerate code transitively. * Because the code in this repo wasn't formatted already, but applying newer `smithy-dafny` code generation automatically formats, all the generated code has trivial layout changes. * Also extracted a manual patch. * Applied a lot of [explicit client downcasting](https://github.com/aws/aws-encryption-sdk-dafny/pull/638/files#diff-b3d9cba935758528ac13c23c2f482d6a09d771122004103605b346e3da5f3cecR29-R33) to account for the change in `smithy-dafny` Note that this changes the Makefile targets as a result: * There is a default value for `CODEGEN_CLI_ROOT` (the `smithy-dafny` submodule copy) so that variable is now optional * Targets like `polymorph_codegen` also now apply to dependencies transitively, just like targets such as `transpile_java`. Because the current state of the MPL submodule doesn't use the same smithy-dafny version or Makefile targets, this doesn't work by default, so for working locally it will generally be better to only generate for the current library via `make polymorph_codegen PROJECT_DEPENDENCIES=`
1 parent c9ad018 commit cd19979

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1487
-1601
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#
2+
# This local action serves two purposes:
3+
#
4+
# 1. For core workflows like pull.yml and push.yml,
5+
# it is uses to check that the checked in copy of generated code
6+
# matches what the current submodule version of smithy-dafny generates.
7+
# This is important to ensure whenever someone changes the models
8+
# or needs to regenerate to pick up smithy-dafny improvements,
9+
# they don't have to deal with unpleasant surprises.
10+
#
11+
# 2. For workflows that check compatibility with other Dafny versions,
12+
# such as nightly_dafny.yml, it is necessary to regenerate the code
13+
# for that version of Dafny first.
14+
# This is ultimately because some of the code smithy-dafny generates
15+
# is tightly coupled to what code Dafny itself generates.
16+
# A concrete example is that Dafny 4.3 added TypeDescriptors
17+
# as parameters when constructing datatypes like Option and Result.
18+
#
19+
# This is why this is a composite action instead of a reusable workflow:
20+
# the latter executes in a separate runner environment,
21+
# but here we need to actually overwrite the generated code in place
22+
# so that subsequent steps can work correctly.
23+
#
24+
# This action assumes that the given version of Dafny and .NET 6.0.x
25+
# have already been set up, since they are used to format generated code.
26+
#
27+
# Note that recursively generating code doesn't currently work in this repo
28+
# with the version of the mpl pinned by the submodule,
29+
# because the SharedMakefileV2.mk in it doesn't work with newer versions of smithy-dafny.
30+
# Therefore by default we don't recursively regenerate code
31+
# (accomplished by setting the POLYMORPH_DEPENDENCIES environment variable to "").
32+
# If `update-and-regenerate-mpl` is true, we first pull the latest mpl,
33+
# which is necessary both for Makefile compatibility and so we can regenerate mpl code
34+
# for compatibility with newer versions of Dafny.
35+
#
36+
37+
name: "Polymorph code generation"
38+
description: "Regenerates code using smithy-dafny, and optionally checks that the result matches the checked in state"
39+
inputs:
40+
dafny:
41+
description: "The Dafny version to run"
42+
required: true
43+
type: string
44+
library:
45+
description: "Name of the library to regenerate code for"
46+
required: true
47+
type: string
48+
diff-generated-code:
49+
description: "Diff regenerated code against committed state"
50+
required: true
51+
type: boolean
52+
update-and-regenerate-mpl:
53+
description: "Locally update MPL to the tip of master and regenerate its code too"
54+
required: false
55+
default: false
56+
type: boolean
57+
runs:
58+
using: "composite"
59+
steps:
60+
- name: Update MPL submodule locally if requested
61+
if: inputs.update-and-regenerate-mpl == 'true'
62+
shell: bash
63+
run: |
64+
git submodule update --init --recursive --remote --merge mpl
65+
66+
- name: Don't regenerate dependencies unless requested
67+
id: dependencies
68+
shell: bash
69+
run: |
70+
echo "PROJECT_DEPENDENCIES=${{ inputs.update-and-regenerate-mpl != 'true' && 'PROJECT_DEPENDENCIES=' || '' }}" >> $GITHUB_OUTPUT
71+
72+
- name: Regenerate Dafny code using smithy-dafny
73+
# Unfortunately Dafny codegen doesn't work on Windows:
74+
# https://github.com/smithy-lang/smithy-dafny/issues/317
75+
if: runner.os != 'Windows'
76+
working-directory: ./${{ inputs.library }}
77+
shell: bash
78+
run: |
79+
make polymorph_dafny ${{ steps.dependencies.outputs.PROJECT_DEPENDENCIES }}
80+
81+
- name: Set up prettier in MPL
82+
if: inputs.update-and-regenerate-mpl == 'true'
83+
shell: bash
84+
# Annoyingly, prettier has to be installed in each library individually.
85+
# And this is only necessary or even possible if we've updated the mpl submodule.
86+
run: |
87+
make -C mpl/AwsCryptographyPrimitives setup_prettier
88+
make -C mpl/AwsCryptographicMaterialProviders setup_prettier
89+
make -C mpl/ComAmazonawsKms setup_prettier
90+
make -C mpl/ComAmazonawsDynamodb setup_prettier
91+
92+
- name: Regenerate Java code using smithy-dafny
93+
# npx seems to be unavailable on Windows GHA runners,
94+
# so we don't regenerate Java code on them either.
95+
if: runner.os != 'Windows'
96+
working-directory: ./${{ inputs.library }}
97+
shell: bash
98+
# smithy-dafny also formats generated code itself now,
99+
# so prettier is a necessary dependency.
100+
run: |
101+
make setup_prettier
102+
make polymorph_java ${{ steps.dependencies.outputs.PROJECT_DEPENDENCIES }}
103+
104+
- name: Regenerate .NET code using smithy-dafny
105+
working-directory: ./${{ inputs.library }}
106+
shell: bash
107+
run: |
108+
make polymorph_dotnet ${{ steps.dependencies.outputs.PROJECT_DEPENDENCIES }}
109+
110+
- name: Check regenerated code against commited code
111+
# Composite action inputs seem to not actually support booleans properly for some reason
112+
if: inputs.diff-generated-code == 'true'
113+
working-directory: ./${{ inputs.library }}
114+
shell: bash
115+
run: |
116+
make check_polymorph_diff

.github/workflows/daily_ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ on:
66
- cron: "00 15 * * 1-5"
77

88
jobs:
9+
daily-ci-codegen:
10+
# Don't run the cron builds on forks
11+
if: github.event_name != 'schedule' || github.repository_owner == 'aws'
12+
uses: ./.github/workflows/library_dafny_codegen.yml
13+
with:
14+
dafny: '4.2.0'
915
daily-ci-verification:
1016
# Don't run the cron builds on forks
1117
if: github.event_name != 'schedule' || github.repository_owner == 'aws'

.github/workflows/library_codegen.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# This workflow regenerates code using smithy-dafny and checks that the output matches what's checked in.
2+
name: Library Code Generation
3+
on:
4+
workflow_call:
5+
inputs:
6+
dafny:
7+
description: "The Dafny version to run"
8+
required: true
9+
type: string
10+
11+
jobs:
12+
code-generation:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
library:
17+
[
18+
AwsEncryptionSDK,
19+
]
20+
# Note dotnet is only used for formatting generated code
21+
# in this workflow
22+
dotnet-version: ["6.0.x"]
23+
os: [ubuntu-latest]
24+
runs-on: ${{ matrix.os }}
25+
defaults:
26+
run:
27+
shell: bash
28+
env:
29+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
30+
DOTNET_NOLOGO: 1
31+
steps:
32+
- name: Support longpaths
33+
run: |
34+
git config --global core.longpaths true
35+
36+
- uses: actions/checkout@v4
37+
# The specification submodule is private so we don't have access, but we don't need
38+
# it to verify the Dafny code. Instead we manually pull the submodules we DO need.
39+
- run: git submodule update --init libraries
40+
- run: git submodule update --init --recursive mpl
41+
- run: git submodule update --init smithy-dafny
42+
43+
# Only used to format generated code
44+
# and to translate version strings such as "nightly-latest"
45+
# to an actual DAFNY_VERSION.
46+
- name: Setup Dafny
47+
uses: dafny-lang/[email protected]
48+
with:
49+
dafny-version: ${{ inputs.dafny }}
50+
51+
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
52+
uses: actions/setup-dotnet@v3
53+
with:
54+
dotnet-version: ${{ matrix.dotnet-version }}
55+
56+
- uses: ./.github/actions/polymorph_codegen
57+
with:
58+
dafny: ${{ env.DAFNY_VERSION }}
59+
library: ${{ matrix.library }}
60+
diff-generated-code: true

.github/workflows/library_dafny_verification.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ on:
77
dafny:
88
description: 'The Dafny version to run'
99
required: true
10-
type: string
10+
type: string
11+
regenerate-code:
12+
description: "Regenerate code using smithy-dafny"
13+
required: false
14+
default: false
15+
type: boolean
1116

1217
jobs:
1318
verification:
@@ -31,12 +36,22 @@ jobs:
3136
run: |
3237
git submodule update --init libraries
3338
git submodule update --init --recursive mpl
39+
git submodule update --init smithy-dafny
3440
3541
- name: Setup Dafny
36-
uses: dafny-lang/setup-dafny-action@v1.6.1
42+
uses: dafny-lang/setup-dafny-action@v1.7.0
3743
with:
3844
dafny-version: ${{ inputs.dafny }}
3945

46+
- name: Regenerate code using smithy-dafny if necessary
47+
if: ${{ inputs.regenerate-code }}
48+
uses: ./.github/actions/polymorph_codegen
49+
with:
50+
dafny: ${{ env.DAFNY_VERSION }}
51+
library: ${{ matrix.library }}
52+
diff-generated-code: false
53+
update-and-regenerate-mpl: true
54+
4055
- name: Verify ${{ matrix.library }} Dafny code
4156
shell: bash
4257
working-directory: ./${{ matrix.library }}

.github/workflows/library_interop_tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
run: |
4747
git submodule update --init libraries
4848
git submodule update --init --recursive mpl
49+
git submodule update --init smithy-dafny
4950
5051
- name: Configure AWS Credentials
5152
uses: aws-actions/configure-aws-credentials@v4
@@ -135,6 +136,7 @@ jobs:
135136
run: |
136137
git submodule update --init libraries
137138
git submodule update --init --recursive mpl
139+
git submodule update --init smithy-dafny
138140
139141
- name: Configure AWS Credentials
140142
uses: aws-actions/configure-aws-credentials@v4
@@ -227,6 +229,7 @@ jobs:
227229
run: |
228230
git submodule update --init libraries
229231
git submodule update --init --recursive mpl
232+
git submodule update --init smithy-dafny
230233
231234
- name: Configure AWS Credentials
232235
uses: aws-actions/configure-aws-credentials@v4

.github/workflows/library_java_tests.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
description: 'The Dafny version to run'
99
required: true
1010
type: string
11+
regenerate-code:
12+
description: "Regenerate code using smithy-dafny"
13+
required: false
14+
default: false
15+
type: boolean
1116

1217
jobs:
1318
testJava:
@@ -36,6 +41,7 @@ jobs:
3641
run: |
3742
git submodule update --init libraries
3843
git submodule update --init --recursive mpl
44+
git submodule update --init smithy-dafny
3945
4046
- name: Configure AWS Credentials
4147
uses: aws-actions/configure-aws-credentials@v2
@@ -45,10 +51,19 @@ jobs:
4551
role-session-name: JavaTests
4652

4753
- name: Setup Dafny
48-
uses: dafny-lang/setup-dafny-action@v1.6.1
54+
uses: dafny-lang/setup-dafny-action@v1.7.0
4955
with:
5056
dafny-version: ${{ inputs.dafny }}
5157

58+
- name: Regenerate code using smithy-dafny if necessary
59+
if: ${{ inputs.regenerate-code }}
60+
uses: ./.github/actions/polymorph_codegen
61+
with:
62+
dafny: ${{ env.DAFNY_VERSION }}
63+
library: ${{ matrix.library }}
64+
diff-generated-code: false
65+
update-and-regenerate-mpl: true
66+
5267
- name: Setup Java 8
5368
uses: actions/setup-java@v3
5469
with:

.github/workflows/library_net_tests.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ on:
88
description: 'The Dafny version to run'
99
required: true
1010
type: string
11+
regenerate-code:
12+
description: "Regenerate code using smithy-dafny"
13+
required: false
14+
default: false
15+
type: boolean
1116

1217
env:
1318
# Used in examples
@@ -23,6 +28,7 @@ env:
2328
jobs:
2429
testDotNet:
2530
strategy:
31+
fail-fast: false
2632
matrix:
2733
os: [
2834
windows-latest,
@@ -46,6 +52,7 @@ jobs:
4652
run: |
4753
git submodule update --init libraries
4854
git submodule update --init --recursive mpl
55+
git submodule update --init smithy-dafny
4956
5057
- name: Configure AWS Credentials
5158
uses: aws-actions/configure-aws-credentials@v2
@@ -60,10 +67,19 @@ jobs:
6067
dotnet-version: '6.0.x'
6168

6269
- name: Setup Dafny
63-
uses: dafny-lang/setup-dafny-action@v1.6.1
70+
uses: dafny-lang/setup-dafny-action@v1.7.0
6471
with:
6572
dafny-version: ${{ inputs.dafny }}
6673

74+
- name: Regenerate code using smithy-dafny if necessary
75+
if: ${{ inputs.regenerate-code }}
76+
uses: ./.github/actions/polymorph_codegen
77+
with:
78+
dafny: ${{ env.DAFNY_VERSION }}
79+
library: AwsEncryptionSDK
80+
diff-generated-code: false
81+
update-and-regenerate-mpl: true
82+
6783
- name: Download Dependencies
6884
working-directory: ./AwsEncryptionSDK
6985
run: make setup_net

.github/workflows/manual.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow invokes other workflows with the requested Dafny build.
2+
# It is primarily meant for manual compatibility testing,
3+
# such as trying out what the next pending nightly build will do ahead of time.
4+
name: Manual CI
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
dafny:
10+
description: "The Dafny version to use"
11+
required: true
12+
type: string
13+
regenerate-code:
14+
description: "Regenerate code using smithy-dafny"
15+
required: false
16+
default: true
17+
type: boolean
18+
19+
jobs:
20+
manual-ci-verification:
21+
uses: ./.github/workflows/library_dafny_verification.yml
22+
with:
23+
dafny: ${{ inputs.dafny }}
24+
regenerate-code: ${{ inputs.regenerate-code }}
25+
# manual-ci-java:
26+
# uses: ./.github/workflows/library_java_tests.yml
27+
# with:
28+
# dafny: ${{ inputs.dafny }}
29+
# regenerate-code: ${{ inputs.regenerate-code }}
30+
manual-ci-net:
31+
uses: ./.github/workflows/library_net_tests.yml
32+
with:
33+
dafny: ${{ inputs.dafny }}
34+
regenerate-code: ${{ inputs.regenerate-code }}

.github/workflows/nighly_dafny.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ jobs:
1818
uses: ./.github/workflows/library_dafny_verification.yml
1919
with:
2020
dafny: 'nightly-latest'
21+
regenerate-code: true
2122
# dafny-nightly-java:
2223
# if: github.event_name != 'schedule' || github.repository_owner == 'aws'
2324
# uses: ./.github/workflows/library_java_tests.yml
2425
# with:
2526
# dafny: 'nightly-latest'
27+
# regenerate-code: true
2628
dafny-nightly-net:
2729
if: github.event_name != 'schedule' || github.repository_owner == 'aws'
2830
uses: ./.github/workflows/library_net_tests.yml
2931
with:
3032
dafny: 'nightly-latest'
33+
regenerate-code: true

0 commit comments

Comments
 (0)