Syntax tweak in GHA pipeline for smoke test #27
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: Publish & Deploy Smoke Test | |
on: | |
push: | |
branches: [main, feature/smoke-tests] | |
workflow_dispatch: | |
inputs: | |
environment: | |
type: environment | |
description: The environment to deploy to. | |
jobs: | |
detect-environments: | |
runs-on: ubuntu-latest | |
outputs: | |
environments: ${{ steps.environments.outputs.result }} | |
steps: | |
- uses: actions/github-script@v6 | |
id: environments | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
result-encoding: json | |
script: | | |
if (context.payload?.inputs?.environment) return [context.payload?.inputs?.environment]; | |
const {data: {environments}} = | |
await github.request(`GET /repos/${process.env.GITHUB_REPOSITORY}/environments`); | |
return environments.map(e => e.name) | |
build-package: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Prepare package directory | |
working-directory: ./tests/smoke | |
run: | | |
sudo -s sh -c 'mkdir -p package/python' | |
sudo -s sh -c 'cp src/* ./package/python/.' | |
- name: Create smoke test code package ZIP | |
working-directory: ./tests/smoke | |
run: | | |
sudo -s sh -c 'zip -r smoke-test-package.zip ./package/*' | |
- name: Upload smoke test package artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: smoke-test-package | |
path: ./tests/smoke/smoke-test-package.zip | |
retention-days: 1 | |
publish-deploy: | |
runs-on: ubuntu-latest | |
needs: [detect-environments, build-package] | |
strategy: | |
matrix: | |
environment: ${{ fromJSON(needs.detect-environments.outputs.environments) }} | |
environment: ${{ matrix.environment }} | |
steps: | |
# - name: Set up Python | |
# uses: actions/setup-python@v5 | |
# with: | |
# python-version: 3.12 | |
- name: Install aws cli | |
run: | | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip -q awscliv2.zip | |
sudo ./aws/install --update | |
sudo apt-get update | |
sudo apt-get install -y rsync | |
- name: Set up AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1-node16 | |
with: | |
aws-access-key-id: ${{ secrets.DEPLOY_AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.DEPLOY_AWS_SECRET_ACCESS_KEY }} | |
aws-region: eu-west-2 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: smoke-test-package | |
path: ./smoke-test-package.zip | |
- name: Update AWS Synthetics Canary function code in development environment | |
if: ${{ matrix.environment == 'development' }} | |
run: | | |
aws synthetics update-canary \ | |
--name www \ | |
--code ZipFile=./smoke-test-package.zip,Handler=smoke_canary.handler |