Consume .NET daily builds #1443
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build | |
on: | |
push: | |
branches: [ main ] | |
paths-ignore: | |
- '**/*.md' | |
- '**/*.gitignore' | |
- '**/*.gitattributes' | |
pull_request: | |
branches: | |
- main | |
- dotnet-vnext | |
- dotnet-nightly | |
workflow_dispatch: | |
env: | |
ARTIFACT_NAME: 'lambda' | |
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }} | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
DOTNET_GENERATE_ASPNET_CERTIFICATE: false | |
DOTNET_MULTILEVEL_LOOKUP: 0 | |
DOTNET_NOLOGO: true | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1 | |
LAMBDA_ARCHITECTURES: 'arm64' | |
LAMBDA_DESCRIPTION: 'Deploy build ${{ github.run_number }} to AWS Lambda via GitHub Actions' | |
LAMBDA_FUNCTION: 'alexa-london-travel' | |
LAMBDA_HANDLER: 'LondonTravel.Skill::MartinCostello.LondonTravel.Skill.AlexaFunctionHandler::HandleAsync' | |
LAMBDA_MEMORY: 256 | |
LAMBDA_ROLE: ${{ vars.AWS_LAMBDA_ROLE }} | |
LAMBDA_RUNTIME: 'provided.al2' | |
LAMBDA_TIMEOUT: 10 | |
NUGET_XMLDOC_MODE: skip | |
TERM: xterm | |
permissions: | |
contents: read | |
jobs: | |
build: | |
name: ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ macos-latest, ubuntu-latest, windows-latest ] | |
include: | |
- os: macos-latest | |
os_name: macos | |
- os: ubuntu-latest | |
os_name: linux | |
- os: windows-latest | |
os_name: windows | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 | |
- name: Build, Test and Package | |
shell: pwsh | |
run: ./build.ps1 | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 | |
with: | |
file: ./artifacts/coverage/coverage.cobertura.xml | |
flags: ${{ matrix.os_name }} | |
- name: Publish artifacts | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
with: | |
name: artifacts-${{ matrix.os_name }} | |
path: ./artifacts | |
- name: Create Lambda ZIP file | |
if: runner.os == 'Linux' | |
run: | | |
cd "./artifacts/publish/LondonTravel.Skill/release_linux-arm64" || exit | |
if [ -f "./bootstrap" ] | |
then | |
chmod +x ./bootstrap | |
fi | |
zip -r "../../../${{ env.LAMBDA_FUNCTION }}.zip" . || exit 1 | |
- name: Publish deployment package | |
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 | |
if: runner.os == 'Linux' && success() | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: ./artifacts/${{ env.LAMBDA_FUNCTION }}.zip | |
if-no-files-found: error | |
deploy-dev: | |
if: | | |
github.event.repository.fork == false && | |
github.ref_name == github.event.repository.default_branch | |
name: dev | |
needs: build | |
concurrency: dev_environment | |
runs-on: ubuntu-latest | |
environment: | |
name: dev | |
permissions: | |
id-token: write | |
steps: | |
- name: Set function name | |
run: | | |
echo "FUNCTION_NAME=${{ env.LAMBDA_FUNCTION }}-dev" >> "$GITHUB_ENV" | |
- name: Download artifacts | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-deploy | |
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-deploy-dev | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Update function code | |
run: | | |
aws lambda update-function-code \ | |
--function-name "${FUNCTION_NAME}" \ | |
--architectures "${LAMBDA_ARCHITECTURES}" \ | |
--zip-file fileb://./${{ env.LAMBDA_FUNCTION }}.zip \ | |
> /dev/null | |
- name: Wait for function code update | |
run: | | |
aws lambda wait function-updated-v2 \ | |
--function-name "${FUNCTION_NAME}" \ | |
> /dev/null | |
- name: Update function configuration | |
run: | | |
aws lambda update-function-configuration \ | |
--function-name "${FUNCTION_NAME}" \ | |
--description "${LAMBDA_DESCRIPTION}" \ | |
--handler ${{ env.LAMBDA_HANDLER }} \ | |
--memory-size ${{ env.LAMBDA_MEMORY }} \ | |
--role ${{ env.LAMBDA_ROLE }} \ | |
--runtime ${{ env.LAMBDA_RUNTIME }} \ | |
--timeout ${{ env.LAMBDA_TIMEOUT }} \ | |
> /dev/null | |
- name: Wait for function configuration update | |
run: | | |
aws lambda wait function-updated-v2 \ | |
--function-name "${FUNCTION_NAME}" \ | |
> /dev/null | |
tests-dev: | |
name: tests-dev | |
needs: deploy-dev | |
runs-on: ubuntu-latest | |
concurrency: dev_environment | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-test | |
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-tests-dev | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Run end-to-end tests | |
shell: pwsh | |
run: dotnet test ./test/LondonTravel.Skill.EndToEndTests --configuration Release --logger "GitHubActions;report-warnings=false" | |
env: | |
LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION }}-dev | |
deploy-prod: | |
name: production | |
needs: tests-dev | |
runs-on: ubuntu-latest | |
concurrency: production_environment | |
environment: | |
name: production | |
permissions: | |
id-token: write | |
steps: | |
- name: Set function name | |
run: | | |
echo "FUNCTION_NAME=${{ env.LAMBDA_FUNCTION }}" >> "$GITHUB_ENV" | |
- name: Download artifacts | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
name: lambda | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-deploy | |
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-deploy-production | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Update function code | |
run: | | |
aws lambda update-function-code \ | |
--function-name "${FUNCTION_NAME}" \ | |
--architectures "${LAMBDA_ARCHITECTURES}" \ | |
--zip-file fileb://./${{ env.LAMBDA_FUNCTION }}.zip \ | |
> /dev/null | |
- name: Wait for function code update | |
run: | | |
aws lambda wait function-updated-v2 \ | |
--function-name "${FUNCTION_NAME}" \ | |
> /dev/null | |
- name: Update function configuration | |
run: | | |
aws lambda update-function-configuration \ | |
--function-name "${FUNCTION_NAME}" \ | |
--description "${LAMBDA_DESCRIPTION}" \ | |
--handler ${{ env.LAMBDA_HANDLER }} \ | |
--memory-size ${{ env.LAMBDA_MEMORY }} \ | |
--role ${{ env.LAMBDA_ROLE }} \ | |
--runtime ${{ env.LAMBDA_RUNTIME }} \ | |
--timeout ${{ env.LAMBDA_TIMEOUT }} \ | |
> /dev/null | |
- name: Wait for function configuration update | |
run: | | |
aws lambda wait function-updated-v2 \ | |
--function-name "${FUNCTION_NAME}" \ | |
> /dev/null | |
tests-prod: | |
needs: deploy-prod | |
runs-on: ubuntu-latest | |
concurrency: production_environment | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
- name: Setup .NET SDK | |
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@04b98b3f9e85f563fb061be8751a0352327246b0 # v3.0.1 | |
with: | |
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github-actions-test | |
role-session-name: ${{ github.event.repository.name }}-${{ github.run_id }}-tests-production | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Run end-to-end tests | |
shell: pwsh | |
run: dotnet test ./test/LondonTravel.Skill.EndToEndTests --configuration Release --logger "GitHubActions;report-warnings=false" | |
env: | |
LAMBDA_FUNCTION_NAME: ${{ env.LAMBDA_FUNCTION }} |