Skip to content

Commit

Permalink
Add smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentao-Kuang committed May 3, 2024
1 parent 709ca4b commit 85764e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
44 changes: 37 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Bundle Assets Into Cotar
run: |
./scripts/bmc.sh bundle-assets --assets $PWD/assets/ --output $PWD/assets.tar.co
./scripts/bmc.sh ./index.cjs bundle-assets --assets $PWD/assets/ --output $PWD/assets.tar.co
ASSETS_HASH=$(ls assets*.tar.co)
echo "ASSETS_HASH=${ASSETS_HASH}" >> $GITHUB_ENV
echo "ASSETS_LOCATION_STAGING=s3://linz-basemaps-staging/assets/${ASSETS_HASH}" >> $GITHUB_ENV
Expand All @@ -61,7 +61,7 @@ jobs:

- name: Bundle Config File
run: |
./scripts/bmc.sh bundle --config $PWD/config --output $PWD/config-staging.json --assets ${ASSETS_LOCATION_STAGING} --cache s3://linz-basemaps-staging/basemaps-config/cache/
./scripts/bmc.sh ./index.cjs bundle --config $PWD/config --output $PWD/config-staging.json --assets ${ASSETS_LOCATION_STAGING} --cache s3://linz-basemaps-staging/basemaps-config/cache/
CONFIG_HASH_STAGING=$(cat config-staging.json | jq .hash -r)
echo "CONFIG_LOCATION_STAGING=s3://linz-basemaps-staging/config/config-${CONFIG_HASH_STAGING}.json.gz" >> $GITHUB_ENV
Expand All @@ -82,7 +82,7 @@ jobs:
- name: Compare To Production
run: |
aws s3 cp s3://linz-basemaps/config/config-latest.json.gz .
./scripts/bmc.sh import --config ${CONFIG_LOCATION_STAGING} --output $PWD/changes.md --target $PWD/config-latest.json.gz
./scripts/bmc.sh ./index.cjs import --config ${CONFIG_LOCATION_STAGING} --output $PWD/changes.md --target $PWD/config-latest.json.gz
- name: (Pull Request) Update Description
if: github.ref != 'refs/heads/master' && github.event_name == 'pull_request'
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:

- name: Import config
run: |
./scripts/bmc.sh import --config ${CONFIG_PATH} --commit
./scripts/bmc.sh ./index.cjs import --config ${CONFIG_PATH} --commit
# Compare and deploy to prod
deploy-prod:
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
aws s3 cp assets-current.tar.co ${ASSETS_LOCATION_PROD}
./scripts/bmc.sh bundle --config $PWD/config-current.json.gz --output $PWD/config-prod.json --assets ${ASSETS_LOCATION_PROD} --cache s3://linz-basemaps-staging/basemaps-config/cache/
./scripts/bmc.sh ./index.cjs bundle --config $PWD/config-current.json.gz --output $PWD/config-prod.json --assets ${ASSETS_LOCATION_PROD} --cache s3://linz-basemaps-staging/basemaps-config/cache/
CONFIG_HASH_PROD=$(cat config-prod.json | jq .hash -r)
echo "CONFIG_LOCATION_PROD=s3://linz-basemaps/config/config-${CONFIG_HASH_PROD}.json.gz" >> $GITHUB_ENV
Expand All @@ -183,7 +183,37 @@ jobs:
- name: Import config
run: |
./scripts/bmc.sh import --config ${CONFIG_LOCATION_PROD} --commit
./scripts/bmc.sh ./index.cjs mport --config ${CONFIG_LOCATION_PROD} --commit
smoke:
permissions:
id-token: write
contents: read
needs: [build]
runs-on: ubuntu-latest
env:
DOCKER_AWS_ENV: -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION -e AWS_DEFAULT_REGION
CONFIG_PATH: ${{ needs.build.outputs.config_path }}
BASEMAPS_HOST: http://localhost:5001
steps:
- uses: actions/checkout@v4

- name: (Smoke) AWS Configure
uses: aws-actions/[email protected]
with:
aws-region: ap-southeast-2
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_ROLE_SCREENSHOT }}

- name: (Smoke) Start Local Server
run: |
./scripts/bmc.sh ./index.cjs serve --config ${CONFIG_PATH} --port 5001 &
# Wait for the server to start
timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5001/v1/version)" != "200" ]]; do sleep 0.5; done' || false
- name: (Smoke) Run Smoke test
run: ./scripts/bmc.sh --test ./node_modules/@basemaps/smoke/build/

screenshot:
permissions:
Expand All @@ -209,7 +239,7 @@ jobs:

- name: (Screenshot) Screenshot Pull Request Changes
run: |
./scripts/bmc.sh serve --config ${CONFIG_PATH} &
./scripts/bmc.sh ./index.cjs serve --config ${CONFIG_PATH} --port 5000 &
# Wait for the server to start
timeout 30 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' http://localhost:5000/v1/version)" != "200" ]]; do sleep 0.5; done' || false
Expand Down
5 changes: 3 additions & 2 deletions scripts/bmc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# Run the basemaps/cli as a docker container with all the extra environment vars and args passed in
docker run \
--entrypoint node \
-v ${PWD}:${PWD} \
-p 5000:5000 \
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION -e AWS_DEFAULT_REGION \
ghcr.io/linz/basemaps/cli:v7.2.0 \
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e AWS_REGION -e AWS_DEFAULT_REGION -e BASEMAPS_HOST \
ghcr.io/linz/basemaps/cli:v7.3.0-1-gf14d0bab \
"$@"

0 comments on commit 85764e9

Please sign in to comment.