generated from worldbank/template
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor deployment tooling #85
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
dcd575f
Migrate to reusable workflow
alukach 000fc2d
Add tooling for PR preview URL
alukach d052675
Add runs-on
alukach 7a71a4f
Pre-commit
alukach 1761fd3
Refactor triggers
alukach 5a8132f
Bump version
alukach 7613c5b
Add permissions
alukach df98917
Fix working dir
alukach 6289be1
Fix URL output
alukach 4e7b363
Fix comment find
alukach d164bfe
Add tooling to tear down PR preview
alukach 360d07f
Fix commenting
alukach 3a75870
Fix
alukach 6758230
Run tests on all pushes
alukach ec0f7f4
Refactor
alukach f223e77
Fix
alukach 5288c89
Expand events
alukach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,77 @@ | ||
name: Run Tests | ||
|
||
on: [push, pull_request] | ||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Install Poetry | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install poetry | ||
|
||
- name: Install dependencies | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry install --with test | ||
|
||
- name: install lib postgres | ||
uses: nyurik/action-setup-postgis@v2 | ||
|
||
- name: Run pre-commit | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry run pre-commit run --all-files | ||
|
||
- name: Run tests | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry run python -m pytest --benchmark-skip tests | ||
env: | ||
PGHOST: localhost | ||
PGPORT: 5432 | ||
PGDATABASE: mydatabase | ||
PGUSER: myuser | ||
PGPASSWORD: mypassword | ||
PGTABLENAME: space2stats | ||
S3_BUCKET_NAME: test-bucket | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Install Poetry | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install poetry | ||
|
||
- name: Install dependencies | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry install --with test | ||
|
||
- name: install lib postgres | ||
uses: nyurik/action-setup-postgis@v2 | ||
|
||
- name: Run pre-commit | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry run pre-commit run --all-files | ||
|
||
- name: Run tests | ||
working-directory: ./space2stats_api/src | ||
run: | | ||
poetry run python -m pytest --benchmark-skip tests | ||
env: | ||
PGHOST: localhost | ||
PGPORT: 5432 | ||
PGDATABASE: mydatabase | ||
PGUSER: myuser | ||
PGPASSWORD: mypassword | ||
PGTABLENAME: space2stats | ||
S3_BUCKET_NAME: test-bucket | ||
|
||
deploy-to-dev: | ||
if: ${{ github.event_name == 'pull_request' }} | ||
uses: "./.github/workflows/deploy.yml" | ||
needs: test | ||
with: | ||
environment: Space2Stats API Dev | ||
stage: pr-${{ github.event.pull_request.number }} | ||
pr_number: ${{ github.event.pull_request.number }} | ||
secrets: inherit | ||
|
||
deploy-to-production: | ||
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | ||
uses: "./.github/workflows/deploy.yml" | ||
needs: test | ||
with: | ||
environment: Space2Stats API Prod | ||
stage: prod | ||
secrets: inherit | ||
|
||
destroy-pr-preview: | ||
if: ${{ github.event.action == 'closed' }} | ||
uses: "./.github/workflows/deploy.yml" | ||
with: | ||
environment: Space2Stats API Dev | ||
stage: pr-${{ github.event.pull_request.number }} | ||
|
||
secrets: inherit |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Deploy | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
type: string | ||
required: true | ||
stage: | ||
type: string | ||
required: true | ||
pr-number: | ||
type: number | ||
required: false | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
build: | ||
concurrency: ${{ inputs.environment }} | ||
environment: ${{ inputs.environment }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install AWS CDK | ||
run: npm install -g aws-cdk | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: arn:aws:iam::017820688988:role/Space2Stats-Deploy-Role | ||
aws-region: ${{ vars.CDK_DEFAULT_REGION }} | ||
|
||
- name: Install CDK dependencies | ||
working-directory: ./space2stats_api/cdk | ||
run: | | ||
pip install -r requirements-cdk.txt | ||
|
||
- name: Deploy CDK stack to staging | ||
working-directory: ./space2stats_api/cdk | ||
env: | ||
STAGE: ${{ inputs.stage }} | ||
PGHOST: ${{ secrets.PGHOST }} | ||
PGPORT: ${{ secrets.PGPORT }} | ||
PGDATABASE: ${{ secrets.PGDATABASE }} | ||
PGUSER: ${{ secrets.PGUSER }} | ||
PGPASSWORD: ${{ secrets.PGPASSWORD }} | ||
PGTABLENAME: ${{ secrets.PGTABLENAME }} | ||
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }} | ||
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }} | ||
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }} | ||
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }} | ||
run: cdk deploy --require-approval never --outputs-file outputs.json | ||
|
||
- name: Get API URL | ||
id: get-api-url | ||
working-directory: ./space2stats_api/cdk | ||
run: | | ||
echo "api-url=$(jq -r '."Space2Stats-${{ inputs.stage }}".ApiGatewayUrl' outputs.json)" >> $GITHUB_OUTPUT | ||
|
||
- name: Find Comment | ||
uses: peter-evans/find-comment@v3 | ||
id: find-comment | ||
if: ${{ inputs.pr-number }} | ||
with: | ||
issue-number: ${{ inputs.pr-number }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: "PR Deployment Details:" | ||
|
||
- name: Create or update comment with URL | ||
uses: peter-evans/create-or-update-comment@v4 | ||
if: ${{ inputs.pr-number }} | ||
with: | ||
issue-number: ${{ inputs.pr-number }} | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
body: | | ||
PR Deployment Details: | ||
🚀 PR deployed to ${{ steps.get-api-url.outputs.api-url }} | ||
edit-mode: replace |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Destroy Preview Environment | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
type: string | ||
required: true | ||
stage: | ||
type: string | ||
required: true | ||
pr-number: | ||
type: number | ||
required: false | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
build: | ||
concurrency: ${{ inputs.environment }} | ||
environment: ${{ inputs.environment }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install AWS CDK | ||
run: npm install -g aws-cdk | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: arn:aws:iam::017820688988:role/Space2Stats-Deploy-Role | ||
aws-region: ${{ vars.CDK_DEFAULT_REGION }} | ||
|
||
- name: Install CDK dependencies | ||
working-directory: ./space2stats_api/cdk | ||
run: | | ||
pip install -r requirements-cdk.txt | ||
|
||
- name: Deploy CDK stack to staging | ||
working-directory: ./space2stats_api/cdk | ||
env: | ||
STAGE: ${{ inputs.stage }} | ||
PGHOST: ${{ secrets.PGHOST }} | ||
PGPORT: ${{ secrets.PGPORT }} | ||
PGDATABASE: ${{ secrets.PGDATABASE }} | ||
PGUSER: ${{ secrets.PGUSER }} | ||
PGPASSWORD: ${{ secrets.PGPASSWORD }} | ||
PGTABLENAME: ${{ secrets.PGTABLENAME }} | ||
CDK_CERTIFICATE_ARN: ${{ vars.CDK_CERTIFICATE_ARN }} | ||
CDK_DEFAULT_ACCOUNT: ${{ vars.CDK_DEFAULT_ACCOUNT }} | ||
CDK_DEFAULT_REGION: ${{ vars.CDK_DEFAULT_REGION }} | ||
CDK_DOMAIN_NAME: ${{ vars.CDK_DOMAIN_NAME }} | ||
run: cdk destroy --require-approval never | ||
|
||
- name: Find Comment | ||
uses: peter-evans/find-comment@v3 | ||
id: find-comment | ||
if: ${{ inputs.pr-number }} | ||
with: | ||
issue-number: ${{ inputs.pr-number }} | ||
comment-author: "github-actions[bot]" | ||
body-includes: "PR Deployment Details:" | ||
|
||
- name: Create or update comment with URL | ||
uses: peter-evans/create-or-update-comment@v4 | ||
if: ${{ inputs.pr-number }} | ||
with: | ||
issue-number: ${{ inputs.pr-number }} | ||
comment-id: ${{ steps.find-comment.outputs.comment-id }} | ||
body: | | ||
Removed PR Preview Environment. | ||
edit-mode: append |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be calling destroy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, caught in 324c3cb and I am refining in #78. Feel free to have a 👀