Skip to content

improv(build): allow to specify PR number when running e2e tests #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/scripts/get_pr_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = async ({ github, context, core }) => {
const prNumber = process.env.PR_NUMBER;

if (prNumber === "") {
core.setFailed(`No PR number was passed. Aborting`);
}

try {
const {
data: { head, base },
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});

core.setOutput("headRef", head.ref);
core.setOutput("headSHA", head.sha);
core.setOutput("baseRef", base.ref);
core.setOutput("baseSHA", base.sha);
} catch (error) {
core.setFailed(
`Unable to retrieve info from PR number ${prNumber}.\n\n Error details: ${error}`
);
throw error;
}
};
110 changes: 58 additions & 52 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
name: run-e2e-tests
name: Run e2e Tests

on:
workflow_dispatch: {}
workflow_dispatch:
inputs:
prNumber:
description: "(Optional) PR Number. If you specify a value the value of the branch field will be ignored."
required: false
default: ""

jobs:
example-and-package-check:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: "Use NodeJS 16"
uses: actions/setup-node@v3
with:
node-version: 16
- name: "Install [email protected]"
run: npm i -g npm@next-8
- name: "Install monorepo packages"
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Install CDK example packages
# Since we are not managing the CDK examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/cdk
run: npm ci
- name: "Setup SAM"
# We use an ad-hoc action so we can specify the SAM CLI version
uses: aws-actions/setup-sam@v2
with:
version: 1.49.0
- name: Install SAM example packages
# Since we are not managing the SAM examples with npm workspaces we install
# the dependencies in a separate step
working-directory: ./examples/sam
run: npm ci
- name: "Test packaging"
run: |
npm run lerna-package
cd examples/cdk
npm install ../../packages/**/dist/aws-lambda-powertools-*
npm run test
package-e2e-tests:
run-e2e-tests-on-utils:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
PR_NUMBER: ${{ inputs.prNumber }}
permissions:
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
contents: read
Expand All @@ -51,28 +23,47 @@ jobs:
version: [12, 14, 16]
fail-fast: false
steps:
- name: "Checkout"
- name: Checkout Repo
uses: actions/checkout@v3
- name: "Use NodeJS"
# If we pass a PR Number when triggering the workflow we will retrieve the PR info and get its headSHA
- name: Extract PR details
id: extract_PR_details
if: ${{ inputs.prNumber != '' }}
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/get_pr_info.js');
await script({github, context, core});
# Only if a PR Number was passed and the headSHA of the PR extracted,
# we checkout the PR at that point in time
- name: Checkout PR code
if: ${{ inputs.prNumber != '' }}
uses: actions/checkout@v3
with:
ref: ${{ steps.extract_PR_details.outputs.headSHA }}
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}
- name: "Install npm@8.x"
- name: Setup npm
run: npm i -g npm@next-8
- name: "Install monorepo packages"
- name: Install dependencies
# This installs all the dependencies of ./packages/*
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: "Configure AWS credentials"
- name: Setup AWS credentials
uses: aws-actions/[email protected]
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
aws-region: eu-west-1
- name: "Run packages integration tests"
- name: Run integration tests on utils
run: |
RUNTIME=nodejs${{ matrix.version }}x npm run test:e2e -w packages/${{ matrix.package }}
layer-e2e-tests:
runs-on: ubuntu-latest
env:
NODE_ENV: dev
PR_NUMBER: ${{ inputs.prNumber }}
permissions:
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
contents: read
Expand All @@ -81,14 +72,30 @@ jobs:
matrix:
version: [12, 14, 16]
steps:
- name: Checkout
- name: Checkout Repo
uses: actions/checkout@v3
# If we pass a PR Number when triggering the workflow we will retrieve the PR info and get its headSHA
- name: Extract PR details
id: extract_PR_details
if: ${{ inputs.prNumber != '' }}
uses: actions/github-script@v6
with:
script: |
const script = require('.github/scripts/get_pr_info.js');
await script({github, context, core});
# Only if a PR Number was passed and the headSHA of the PR extracted,
# we checkout the PR at that point in time
- name: Checkout PR code
if: ${{ inputs.prNumber != '' }}
uses: actions/checkout@v3
- name: Use NodeJS
with:
ref: ${{ steps.extract_PR_details.outputs.headSHA }}
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
# Always use version 16 as we use TypeScript target es2020
node-version: 16
- name: Install npm@8.x
- name: Setup npm
run: npm i -g npm@next-8
- name: "Configure AWS credentials"
uses: aws-actions/[email protected]
Expand All @@ -115,9 +122,8 @@ jobs:
if: steps.cache-node-modules.outputs.cache-hit == 'true'
run: |
npm run build -w packages/commons
- name: "Run layer integration tests"
- name: Run integration test on layers
run: |
npm ci --foreground-scripts
RUNTIME=nodejs${{ matrix.version }}.x npm run test:e2e
working-directory: layer-publisher