From fac5c3aa87f9355d081f76e930b954f29471523f Mon Sep 17 00:00:00 2001 From: Chan <55515281+sichanyoo@users.noreply.github.com> Date: Tue, 24 Dec 2024 10:48:05 -0800 Subject: [PATCH] chore: Make GH workflows pass in staging & refactor using composite actions (#886) * Adjust CI GitHub workflows so it works in staging repo as well. * Add missing cd command * Bring in composite action refactor * Rename composite action --------- Co-authored-by: Sichan Yoo --- .../action.yml | 51 ++++++ .../action.yml | 30 ++++ .github/workflows/continuous-integration.yml | 168 ++++-------------- 3 files changed, 111 insertions(+), 138 deletions(-) create mode 100644 .github/actions/checkout-aws-sdk-swift-composite-action/action.yml create mode 100644 .github/actions/setup-common-tools-composite-action/action.yml diff --git a/.github/actions/checkout-aws-sdk-swift-composite-action/action.yml b/.github/actions/checkout-aws-sdk-swift-composite-action/action.yml new file mode 100644 index 000000000..adf8fc72e --- /dev/null +++ b/.github/actions/checkout-aws-sdk-swift-composite-action/action.yml @@ -0,0 +1,51 @@ +name: 'Checkout aws-sdk-swift composite action' +description: 'A composite action that sets up aws-sdk-swift for the workflow.' +inputs: + AUTOMATION_USER_SSH_PRIVATE_KEY: + description: 'SSH private key for the automation user' + required: true + STAGING_PARTNER_REPO: + description: 'The staging partner repository' + required: true +runs: + using: 'composite' + steps: + - name: Set up SSH key + if: ${{ github.repository != 'smithy-lang/smithy-swift' }} + run: | + mkdir -p ~/.ssh + echo "${{ inputs.AUTOMATION_USER_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan github.com >> ~/.ssh/known_hosts + shell: bash + - name: Select staging aws-sdk-swift branch + if: ${{ github.repository != 'smithy-lang/smithy-swift' }} + run: | + cd smithy-swift + ORIGINAL_REPO_HEAD_REF="$GITHUB_HEAD_REF" \ + DEPENDENCY_REPO_URL="git@github.com:${{ inputs.STAGING_PARTNER_REPO }}.git" \ + ./scripts/ci_steps/select_dependency_branch.sh + shell: bash + - name: Checkout staging aws-sdk-swift + if: ${{ github.repository != 'smithy-lang/smithy-swift' }} + uses: actions/checkout@v4 + with: + repository: ${{ inputs.STAGING_PARTNER_REPO }} + ref: ${{ env.DEPENDENCY_REPO_SHA }} + path: aws-sdk-swift + ssh-key: ${{ inputs.AUTOMATION_USER_SSH_PRIVATE_KEY }} + - name: Select aws-sdk-swift branch + if: ${{ github.repository == 'smithy-lang/smithy-swift' }} + run: | + cd smithy-swift + ORIGINAL_REPO_HEAD_REF="$GITHUB_HEAD_REF" \ + DEPENDENCY_REPO_URL="https://github.com/awslabs/aws-sdk-swift.git" \ + ./scripts/ci_steps/select_dependency_branch.sh + shell: bash + - name: Checkout aws-sdk-swift + if: ${{ github.repository == 'smithy-lang/smithy-swift' }} + uses: actions/checkout@v4 + with: + repository: awslabs/aws-sdk-swift + ref: ${{ env.DEPENDENCY_REPO_SHA }} + path: aws-sdk-swift \ No newline at end of file diff --git a/.github/actions/setup-common-tools-composite-action/action.yml b/.github/actions/setup-common-tools-composite-action/action.yml new file mode 100644 index 000000000..b5998dc1f --- /dev/null +++ b/.github/actions/setup-common-tools-composite-action/action.yml @@ -0,0 +1,30 @@ +name: 'Setup Common Tools' +description: 'A composite action that caches Gradle, caches Swift, and sets up Java.' +runs: + using: 'composite' + steps: + - name: Cache Gradle + uses: actions/cache@v4 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} + restore-keys: | + 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} + 1-${{ runner.os }}-gradle- + - name: Cache Swift + uses: actions/cache@v4 + with: + path: | + ~/Library/Caches/org.swift.swiftpm + ~/.cache/org.swift.swiftpm + key: 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} + restore-keys: | + 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} + 1-${{ runner.os }}-${{ matrix.xcode }}-spm- + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: corretto + java-version: 17 \ No newline at end of file diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 25cb14ced..4f9e575e4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -66,31 +66,8 @@ jobs: sudo xcodebuild -runFirstLaunch - name: Checkout smithy-swift uses: actions/checkout@v4 - - name: Cache Gradle - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - 1-${{ runner.os }}-gradle- - - name: Cache Swift - uses: actions/cache@v4 - with: - path: | - ~/Library/Caches/org.swift.swiftpm - ~/.cache/org.swift.swiftpm - key: 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - restore-keys: | - 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - 1-${{ runner.os }}-${{ matrix.xcode }}-spm- - - name: Setup Java - uses: actions/setup-java@v4 - with: - distribution: corretto - java-version: 17 + - name: Setup common tools + uses: ./.github/actions/setup-common-tools-composite-action - name: Build & Run smithy-swift Kotlin Unit Tests run: ./gradlew build - name: Build & Run smithy-swift Swift Unit Tests @@ -159,55 +136,24 @@ jobs: sudo xcodebuild -runFirstLaunch - name: Checkout smithy-swift uses: actions/checkout@v4 - - name: Select aws-sdk-swift branch - run: | - ORIGINAL_REPO_HEAD_REF="$GITHUB_HEAD_REF" \ - DEPENDENCY_REPO_URL="https://github.com/awslabs/aws-sdk-swift.git" \ - ./scripts/ci_steps/select_dependency_branch.sh - - name: Checkout aws-sdk-swift - uses: actions/checkout@v4 with: - repository: awslabs/aws-sdk-swift - ref: ${{ env.DEPENDENCY_REPO_SHA }} - path: aws-sdk-swift - - name: Move aws-sdk-swift into place - run: mv aws-sdk-swift .. - - name: Cache Gradle - uses: actions/cache@v4 + path: smithy-swift + - name: Checkout aws-sdk-swift with composite action + uses: ./smithy-swift/.github/actions/checkout-aws-sdk-swift-composite-action with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - 1-${{ runner.os }}-gradle- - - name: Cache Swift - uses: actions/cache@v4 - with: - path: | - ~/Library/Caches/org.swift.swiftpm - ~/.cache/org.swift.swiftpm - key: 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - restore-keys: | - 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - 1-${{ runner.os }}-${{ matrix.xcode }}-spm- - - name: Setup Java - uses: actions/setup-java@v4 - with: - distribution: corretto - java-version: 17 + AUTOMATION_USER_SSH_PRIVATE_KEY: ${{ secrets.AUTOMATION_USER_SSH_PRIVATE_KEY }} + STAGING_PARTNER_REPO: ${{ secrets.STAGING_PARTNER_REPO }} + - name: Setup common tools + uses: ./smithy-swift/.github/actions/setup-common-tools-composite-action - name: Tools Versions - run: | - cd ../aws-sdk-swift - ./scripts/ci_steps/log_tool_versions.sh + run: ./aws-sdk-swift/scripts/ci_steps/log_tool_versions.sh - name: Prepare aws-sdk-swift Protocol & Unit Tests run: | - cd ../aws-sdk-swift + cd aws-sdk-swift ./scripts/ci_steps/prepare_protocol_and_unit_tests.sh - name: Build and Run aws-sdk-swift Unit Tests run: | - cd ../aws-sdk-swift + cd aws-sdk-swift set -o pipefail && \ NSUnbufferedIO=YES xcodebuild \ -scheme aws-sdk-swift-Package \ @@ -216,7 +162,7 @@ jobs: | xcbeautify - name: Build and Run aws-sdk-swift Protocol Tests run: | - cd ../aws-sdk-swift/codegen + cd aws-sdk-swift/codegen set -o pipefail && \ NSUnbufferedIO=YES xcodebuild \ -scheme aws-sdk-swift-protocol-tests-Package \ @@ -238,8 +184,8 @@ jobs: env: ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true steps: - - name: Checkout Sources - uses: actions/checkout@v3 + - name: Checkout smithy-swift + uses: actions/checkout@v4 - name: Install openssl run: | if [ -x "$(command -v apt)" ]; then @@ -247,31 +193,8 @@ jobs: else yum install -y openssl-devel which fi - - name: Cache Gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - 1-${{ runner.os }}-gradle- - - name: Cache Swift - uses: actions/cache@v3 - with: - path: | - ~/Library/Caches/org.swift.swiftpm - ~/.cache/org.swift.swiftpm - key: 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - restore-keys: | - 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - 1-${{ runner.os }}-${{ matrix.xcode }}-spm- - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: corretto - java-version: 17 + - name: Setup common tools + uses: ./.github/actions/setup-common-tools-composite-action - name: Build & Run Kotlin Unit Tests run: ./gradlew build - name: Build & Run Swift Unit Tests @@ -291,21 +214,6 @@ jobs: env: ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true steps: - - name: Checkout Sources - uses: actions/checkout@v3 - - name: Select aws-sdk-swift branch - run: | - ORIGINAL_REPO_HEAD_REF="$GITHUB_HEAD_REF" \ - DEPENDENCY_REPO_URL="https://github.com/awslabs/aws-sdk-swift.git" \ - ./scripts/ci_steps/select_dependency_branch.sh - - name: Checkout aws-sdk-swift - uses: actions/checkout@v3 - with: - repository: awslabs/aws-sdk-swift - ref: ${{ env.DEPENDENCY_REPO_SHA }} - path: aws-sdk-swift - - name: Move aws-sdk-swift into place - run: mv aws-sdk-swift .. - name: Install openssl run: | if [ -x "$(command -v apt)" ]; then @@ -313,48 +221,32 @@ jobs: else yum install -y openssl-devel which fi - - name: Cache Gradle - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - restore-keys: | - 1-${{ runner.os }}-gradle-${{ hashFiles('settings.gradle.kts', 'gradle/wrapper/gradle-wrapper.properties') }} - 1-${{ runner.os }}-gradle- - - name: Cache Swift - uses: actions/cache@v3 + - name: Checkout smithy-swift + uses: actions/checkout@v4 with: - path: | - ~/Library/Caches/org.swift.swiftpm - ~/.cache/org.swift.swiftpm - key: 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - restore-keys: | - 1-${{ runner.os }}-${{ matrix.xcode }}-spm-${{ hashFiles('Package.swift') }} - 1-${{ runner.os }}-${{ matrix.xcode }}-spm- - - name: Setup Java - uses: actions/setup-java@v3 + path: smithy-swift + - name: Checkout aws-sdk-swift with composite action + uses: ./smithy-swift/.github/actions/checkout-aws-sdk-swift-composite-action with: - distribution: corretto - java-version: 17 + AUTOMATION_USER_SSH_PRIVATE_KEY: ${{ secrets.AUTOMATION_USER_SSH_PRIVATE_KEY }} + STAGING_PARTNER_REPO: ${{ secrets.STAGING_PARTNER_REPO }} + - name: Setup common tools + uses: ./smithy-swift/.github/actions/setup-common-tools-composite-action - name: Tools Versions - run: | - cd ../aws-sdk-swift - ./scripts/ci_steps/log_tool_versions.sh + run: ./aws-sdk-swift/scripts/ci_steps/log_tool_versions.sh - name: Prepare aws-sdk-swift Protocol & Unit Tests run: | - cd ../aws-sdk-swift + cd aws-sdk-swift ./scripts/ci_steps/prepare_protocol_and_unit_tests.sh - name: Build and Run aws-sdk-swift Unit Tests run: | - cd ../aws-sdk-swift + cd aws-sdk-swift swift test - name: Build and Run aws-sdk-swift Protocol Tests run: | export AWS_REGION=us-west-2 export AWS_ACCESS_KEY_ID=test-key-id export AWS_SECRET_ACCESS_KEY=test-secret-access-key - cd ../aws-sdk-swift/codegen + cd aws-sdk-swift/codegen swift test