From f275395ba22606f86b98bce10d4d03e48bd717d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 22:27:25 +0200 Subject: [PATCH 01/13] add integration test for the archive plugin --- .../{examples_matrix.yml => examples.yml} | 52 ++++++++++++++++++- .github/workflows/pull_request.yml | 6 ++- 2 files changed, 54 insertions(+), 4 deletions(-) rename .github/workflows/{examples_matrix.yml => examples.yml} (59%) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples.yml similarity index 59% rename from .github/workflows/examples_matrix.yml rename to .github/workflows/examples.yml index fb9cca41..bb532fcf 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples.yml @@ -11,6 +11,14 @@ on: # type: sequence # description: "The examples to run." # required: true + examples_enabled: + type: boolean + description: "Boolean to enable the compilation of examples. Defaults to true." + default: true + archive_plugin_enabled: + type: boolean + description: "Boolean to enable the test of the archive plugin. Defaults to true." + default: true matrix_linux_command: type: string description: "The command of the current Swift version linux matrix job to execute." @@ -26,8 +34,9 @@ concurrency: cancel-in-progress: true jobs: - linux: - name: Example/${{ matrix.examples }} on Linux ${{ matrix.swift.swift_version }} + test-examples: + name: Test Examples/${{ matrix.examples }} on Linux ${{ matrix.swift.swift_version }} + if: ${{ inputs.examples_enabled }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -78,3 +87,42 @@ jobs: EXAMPLE: ${{ matrix.examples }} run: | ./scripts/integration_tests.sh + echo "✅ The examples compile correctly" + + test-archive-plugin: + name: Test archive plugin + if: ${{ inputs.archive_plugin_enabled }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Mark the workspace as safe + # https://github.com/actions/checkout/issues/766 + run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + - name: Test the archive plugin + env: + EXAMPLE=HelloWorld + OUTPUT_FILE=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/bootstrap + ZIP_FILE=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip + run: | + pushd Examples/${EXAMPLE} + + # package the example (docker and swift toolchain are installed on the GH runner) + echo yes | swift package archive --allow-network-connection docker + + # did the plugin generated a Linux binary? + [ -f ${OUTPUT_FILE} ] + file ${OUTPUT_FILE} | grep --silent ELF + + # did the plugin created a ZIP file? + [ -f ${ZIP_FILE} ] + + # does the ZIP file contain the bootstrap? + unzip -l ${ZIP_FILE} | grep --silent bootstrap + + echo "✅ The archive plugin is OK" + popd diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ad616cdc..0074d1d0 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -27,12 +27,14 @@ jobs: integration-tests: name: Integration Tests - uses: ./.github/workflows/examples_matrix.yml + uses: ./.github/workflows/examples.yml with: + name: "Integration tests" + examples_enabled: true # We should pass the list of examples here, but we can't pass an array as argument # examples: [ "HelloWorld", "APIGateway" ] - name: "Integration tests" matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build" + archive_plugin_enabled: true swift-6-language-mode: name: Swift 6 Language Mode From a32906ec255252068e1ff072aaf328fd5ee3d227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 22:32:48 +0200 Subject: [PATCH 02/13] fix --- .github/workflows/examples.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index bb532fcf..9a203884 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -105,9 +105,9 @@ jobs: run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - name: Test the archive plugin env: - EXAMPLE=HelloWorld - OUTPUT_FILE=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/bootstrap - ZIP_FILE=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip + EXAMPLE: HelloWorld + OUTPUT_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/bootstrap + ZIP_FILE: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip run: | pushd Examples/${EXAMPLE} From 869d1d01a1bf1b7cc8b46962063e77a241a4926a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 22:36:26 +0200 Subject: [PATCH 03/13] fix --- .github/workflows/examples.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 9a203884..ca71b20f 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -112,7 +112,7 @@ jobs: pushd Examples/${EXAMPLE} # package the example (docker and swift toolchain are installed on the GH runner) - echo yes | swift package archive --allow-network-connection docker + echo yes | swift package archive --allow-network-connections docker # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ] From f1bfabb41f8b11105fa085769619a1f2154dfbf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 23:06:38 +0200 Subject: [PATCH 04/13] fix yaml linter --- .github/workflows/examples.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index ca71b20f..0538d42a 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -99,7 +99,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 with: - persist-credentials: false + persist-credentials: false - name: Mark the workspace as safe # https://github.com/actions/checkout/issues/766 run: git config --global --add safe.directory ${GITHUB_WORKSPACE} @@ -112,17 +112,17 @@ jobs: pushd Examples/${EXAMPLE} # package the example (docker and swift toolchain are installed on the GH runner) - echo yes | swift package archive --allow-network-connections docker - + echo yes | swift package archive --allow-network-connections docker + # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ] file ${OUTPUT_FILE} | grep --silent ELF - + # did the plugin created a ZIP file? [ -f ${ZIP_FILE} ] - + # does the ZIP file contain the bootstrap? unzip -l ${ZIP_FILE} | grep --silent bootstrap - + echo "✅ The archive plugin is OK" popd From 058145bf734a148342a31be61e88e0668d7cd35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 23:19:01 +0200 Subject: [PATCH 05/13] fix --- .github/workflows/examples.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 0538d42a..a24c1889 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -112,7 +112,8 @@ jobs: pushd Examples/${EXAMPLE} # package the example (docker and swift toolchain are installed on the GH runner) - echo yes | swift package archive --allow-network-connections docker + which docker + echo yes | swift package archive --allow-network-connections docker --verbose # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ] From 9f6c6abe9f2e816abda8d50b9566a3ee672108fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 23:27:10 +0200 Subject: [PATCH 06/13] increase logging verbosity when required --- Plugins/AWSLambdaPackager/Plugin.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/AWSLambdaPackager/Plugin.swift b/Plugins/AWSLambdaPackager/Plugin.swift index 916e7bc7..61b4aec3 100644 --- a/Plugins/AWSLambdaPackager/Plugin.swift +++ b/Plugins/AWSLambdaPackager/Plugin.swift @@ -101,7 +101,7 @@ struct AWSLambdaPackager: CommandPlugin { try Utils.execute( executable: dockerToolPath, arguments: ["pull", baseImage], - logLevel: .output + logLevel: verboseLogging ? .debug : .output ) } From 45f456eda29c1b1f51d061bfc5790cee89763b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 23:44:23 +0200 Subject: [PATCH 07/13] debug --- .github/workflows/examples.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index a24c1889..9180e31a 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -113,6 +113,9 @@ jobs: # package the example (docker and swift toolchain are installed on the GH runner) which docker + docker info + docker pull swift:amazonlinux2 + /usr/bin/docker pull swift:amazonlinux2 echo yes | swift package archive --allow-network-connections docker --verbose # did the plugin generated a Linux binary? From b4e4f94d0fcc37e506c158923e775e25c9ac76ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Fri, 11 Oct 2024 23:46:10 +0200 Subject: [PATCH 08/13] debug --- .github/workflows/examples.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 9180e31a..6ff4a885 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -115,8 +115,7 @@ jobs: which docker docker info docker pull swift:amazonlinux2 - /usr/bin/docker pull swift:amazonlinux2 - echo yes | swift package archive --allow-network-connections docker --verbose + echo yes | swift package archive --allow-network-connections docker --disable-docker-image-update --verbose # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ] From 5c0b741a615d72458526bd5f021af84e37eeb31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Sat, 12 Oct 2024 00:31:08 +0200 Subject: [PATCH 09/13] cleanup --- .github/workflows/examples.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 6ff4a885..0538d42a 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -112,10 +112,7 @@ jobs: pushd Examples/${EXAMPLE} # package the example (docker and swift toolchain are installed on the GH runner) - which docker - docker info - docker pull swift:amazonlinux2 - echo yes | swift package archive --allow-network-connections docker --disable-docker-image-update --verbose + echo yes | swift package archive --allow-network-connections docker # did the plugin generated a Linux binary? [ -f ${OUTPUT_FILE} ] From 8ba5bee86b19e0a1a6d5ca0f0e71eeb562c0ecbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Mon, 14 Oct 2024 12:26:24 +0200 Subject: [PATCH 10/13] try to pass an array of examples to test --- .../{examples.yml => integration_tests.yml} | 16 +++++++++------- .github/workflows/pull_request.yml | 9 ++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) rename .github/workflows/{examples.yml => integration_tests.yml} (89%) diff --git a/.github/workflows/examples.yml b/.github/workflows/integration_tests.yml similarity index 89% rename from .github/workflows/examples.yml rename to .github/workflows/integration_tests.yml index 0538d42a..2324a79e 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/integration_tests.yml @@ -7,10 +7,14 @@ on: type: string description: "The name of the workflow used for the concurrency group." required: true - # examples: - # type: sequence - # description: "The examples to run." - # required: true + # We pass the list of examples here, but we can't pass an array as argument + # Instead, we pass a String with a valid JSON array. + # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 + examples: + type: string + description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGAteway' ]\"" + required: true + default: "" examples_enabled: type: boolean description: "Boolean to enable the compilation of examples. Defaults to true." @@ -41,9 +45,7 @@ jobs: strategy: fail-fast: false matrix: - # This should be passed as an argument in input. Can we pass arrays as argument ? - examples: ["HelloWorld", "APIGateway", "S3_AWSSDK", "S3_Soto"] - # examples: ${{ inputs.examples }} + examples: ${{ fromJson(inputs.examples }} # We are using only one Swift version swift: diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6f0e901b..625cc805 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -28,13 +28,16 @@ jobs: integration-tests: name: Integration Tests - uses: ./.github/workflows/examples.yml + uses: ./.github/workflows/integration_tests.yml with: name: "Integration tests" examples_enabled: true - # We should pass the list of examples here, but we can't pass an array as argument - # examples: [ "HelloWorld", "APIGateway" ] matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build" + # We pass the list of examples here, but we can't pass an array as argument + # Instead, we pass a String with a valid JSON array. + # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 + examples: "[ 'HelloWorld', 'APIGateway','S3_AWSSDK', 'S3_Soto' ]" + archive_plugin_enabled: true swift-6-language-mode: From 146b05d4920d2c8e55c272f35c0d3544e593eace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Mon, 14 Oct 2024 12:27:58 +0200 Subject: [PATCH 11/13] fix typo --- .github/workflows/integration_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 2324a79e..0bf8bd83 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -45,7 +45,7 @@ jobs: strategy: fail-fast: false matrix: - examples: ${{ fromJson(inputs.examples }} + examples: ${{ fromJson(inputs.examples) }} # We are using only one Swift version swift: From 862b2f8965ff0a2423048ef7498e199e7cb65795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Mon, 14 Oct 2024 12:29:48 +0200 Subject: [PATCH 12/13] fix lint --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 625cc805..7e1c61b8 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -37,7 +37,7 @@ jobs: # Instead, we pass a String with a valid JSON array. # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 examples: "[ 'HelloWorld', 'APIGateway','S3_AWSSDK', 'S3_Soto' ]" - + archive_plugin_enabled: true swift-6-language-mode: From ad6c6dab76ee642263360f10102aa13a4d40d306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Mon, 14 Oct 2024 12:39:45 +0200 Subject: [PATCH 13/13] fix typo --- .github/workflows/integration_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 0bf8bd83..71b6382a 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -12,7 +12,7 @@ on: # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 examples: type: string - description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGAteway' ]\"" + description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGateway' ]\"" required: true default: "" examples_enabled: @@ -39,7 +39,7 @@ concurrency: jobs: test-examples: - name: Test Examples/${{ matrix.examples }} on Linux ${{ matrix.swift.swift_version }} + name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }} if: ${{ inputs.examples_enabled }} runs-on: ubuntu-latest strategy: