Skip to content
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

feat(devops): Deploy to test environments via CI #3572

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 35 additions & 14 deletions .github/workflows/deploy-to-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ on:
options:
- staging
- beta
- test_fe_1
- test_fe_2
- test_fe_3
- test_fe_4
- test_be_1
canister:
required: true
type: choice
Expand Down Expand Up @@ -41,17 +46,6 @@ jobs:
runs-on: ubuntu-24.04

steps:
- name: Fail if branch is not main
if: ${{ github.ref != 'refs/heads/main' }}
run: |
echo "This workflow can only be manually triggered with workflow_dispatch on the main branch"
exit 1

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Determine Deployment Network
run: |
if [ "${{ github.event_name }}" == "push" ]; then
Expand All @@ -62,25 +56,51 @@ jobs:
echo "CANISTER=${{ github.event.inputs.canister }}" >> $GITHUB_ENV
fi

- name: Check release policy
run: |
if [[ "$NETWORK" == "staging" ]] && [[ "${{ github.ref }}" != "refs/heads/main" ]] ; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this include the check for beta?

for example, the check could pass if the network is beta, but the ref is not main, no? am i missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no rule that beta may have only head of main. Indeed, there is an explicit expectation that we should be able to put feature branches and release candidates (that may not be head of main) on beta.

I have proposed that we have a test environment that always holds the latest release candidate (so that would be the latest tag of the form 1.2.3-rc-4), which is effectively what beta has most of the time at the moment, however that has not been approved.

echo "Only the main branch may be deployed to staging."
exit 1
fi
if [[ "$NETWORK" = test_fe_* ]] && [[ "$CANISTER" != "frontend" ]] ; then
echo "Only a frontend may be deployed to test_fe_* networks"
exit 1
fi
if [[ "$NETWORK" = test_be_* ]] && [[ "$CANISTER" != "backend" ]] ; then
echo "Only a backend may be deployed to test_be_* networks"
exit 1
fi
bitdivine marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just a final ECHO if all checks passed for policy? as feedback for the dev

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the policy passes, the developer will see a check mark next to that step, like this:

Screenshot from 2024-11-15 10-02-00


- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Set Environment Variables Based on Network
run: |
if [ "$NETWORK" == "staging" ]; then
if [[ "$NETWORK" == "staging" ]] || [[ "$NETWORK" = test_fe_* ]]; then
echo "VITE_ETHERSCAN_API_KEY=${{ secrets.VITE_ETHERSCAN_API_KEY_STAGING }}" >> $GITHUB_ENV
echo "VITE_INFURA_API_KEY=${{ secrets.VITE_INFURA_API_KEY_STAGING }}" >> $GITHUB_ENV
echo "VITE_ALCHEMY_API_KEY=${{ secrets.VITE_ALCHEMY_API_KEY_STAGING }}" >> $GITHUB_ENV
echo "VITE_WALLET_CONNECT_PROJECT_ID=${{ secrets.VITE_WALLET_CONNECT_PROJECT_ID_STAGING }}" >> $GITHUB_ENV
echo "VITE_OISY_URL=${{ secrets.VITE_OISY_URL_STAGING }}" >> $GITHUB_ENV
echo "VITE_AIRDROP=${{ secrets.VITE_AIRDROP_STAGING }}" >> $GITHUB_ENV
echo "VITE_AIRDROP_COMPLETED=${{ secrets.VITE_AIRDROP_COMPLETED_STAGING }}" >> $GITHUB_ENV
echo "VITE_COINGECKO_API_KEY=${{ secrets.VITE_COINGECKO_API_KEY_STAGING }}" >> $GITHUB_ENV
echo "VITE_JUNO_SATELLITE_ID=${{ secrets.VITE_JUNO_SATELLITE_ID_STAGING }}" >> $GITHUB_ENV
echo "VITE_JUNO_ORBITER_ID=${{ secrets.VITE_JUNO_ORBITER_ID_STAGING }}" >> $GITHUB_ENV
echo "VITE_POUH_ENABLED=${{ secrets.VITE_POUH_ENABLED_STAGING }}" >> $GITHUB_ENV
echo "VITE_AUTH_ALTERNATIVE_ORIGINS=${{ secrets.VITE_AUTH_ALTERNATIVE_ORIGINS_STAGING }}" >> $GITHUB_ENV
echo "VITE_AUTH_DERIVATION_ORIGIN=${{ secrets.VITE_AUTH_DERIVATION_ORIGIN_STAGING }}" >> $GITHUB_ENV
echo "VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED=${{ secrets.VITE_BTC_TO_CKBTC_EXCHANGE_ENABLED_STAGING }}" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_DEV=${{ secrets.VITE_ONRAMPER_API_KEY_DEV_STAGING }}" >> $GITHUB_ENV
echo "VITE_ONRAMPER_API_KEY_PROD=${{ secrets.VITE_ONRAMPER_API_KEY_PROD_STAGING }}" >> $GITHUB_ENV
if [[ "$NETWORK" == "staging" ]]; then
echo "VITE_AUTH_ALTERNATIVE_ORIGINS=${{ secrets.VITE_AUTH_ALTERNATIVE_ORIGINS_STAGING }}" >> $GITHUB_ENV
echo "VITE_OISY_URL=${{ secrets.VITE_OISY_URL_STAGING }}" >> $GITHUB_ENV
else
SUBDOMAIN="fe${NETWORK#test_fe_}" # E.g. test_fe_1 -> fe1
echo "VITE_AUTH_ALTERNATIVE_ORIGINS=${{ secrets.VITE_AUTH_ALTERNATIVE_ORIGINS_STAGING }}" | sed "s/staging/$SUBDOMAIN/g" >> $GITHUB_ENV
echo "VITE_OISY_URL=${{ secrets.VITE_OISY_URL_STAGING }}" | sed "s/staging/$SUBDOMAIN/g" >> $GITHUB_ENV
fi
{
echo 'DFX_DEPLOY_KEY<<EOF'
echo "${{ secrets.DFX_DEPLOY_KEY_STAGING }}"
Expand Down Expand Up @@ -142,6 +162,7 @@ jobs:
dfx identity import --disable-encryption --force default "$key_pem"
rm "$key_pem"
dfx identity use default
dfx identity get-principal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a "good to have", right? it will print the principal so that we have more info, that's the idea?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It is not enough for the code to be correct, we need to be able to verify that it is working correctly. It's hard to verify that the expected principal is being used when it's invisible. :-) Another point where we need better visibility for verification is the env vars, but that will be a bigger change so I didn't commit that.


- name: Pre-build
run: npm run build
Expand Down