Merge pull request #605 from cocrafts/ltminhthu/profit-and-lost #145
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: CD Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- "main" | |
- "staging" | |
- "dev" | |
jobs: | |
release: | |
environment: ${{ github.ref == 'refs/heads/main' && 'production' || (github.ref == 'refs/heads/staging' && 'staging' || 'development') }} | |
runs-on: ubuntu-latest | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
DEPLOYMENT_STAGE: ${{ github.ref == 'refs/heads/main' && 'production' || (github.ref == 'refs/heads/staging' && 'staging' || 'development') }} | |
CI: false | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
registry-url: https://npm.pkg.github.com/ | |
- name: Install @metacraft/cli | |
run: npm i --location=global @metacraft/cli@latest | |
- name: Setup Yarn | |
run: corepack enable && yarn set version stable | |
- name: Install dependencies | |
run: yarn | |
- name: Execute eslint | |
run: yarn lint | |
- name: Execute type check with tsc | |
run: yarn type-check | |
- name: Create .env.test file for testing | |
run: | | |
touch .env.test | |
echo "${{ secrets.WALLET_TEST_ENV_FILE }}" >> apps/wallet/.env.test | |
- name: Run test cases | |
run: yarn test | |
- name: Set branch name | |
id: branch | |
run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}" | |
- name: Inspect stacks from commit message | |
id: inspect_stacks_from_commit_message | |
run: | | |
commit=$(git log --format="%B" -n 1) | |
stack_regex="\[(document|landing|wallet)\]" | |
remove_brackets_regex="(\w+)" | |
stacks_str=$(echo $commit | grep -oE $stack_regex | grep -oE $remove_brackets_regex | tr "\n" " ") | |
echo "stacks_str=\"$stacks_str\"" >> $GITHUB_OUTPUT | |
- name: Create .env file | |
run: | | |
touch .env.$DEPLOYMENT_STAGE | |
echo "${{ secrets.WALLET_ENV_FILE }}" >> apps/wallet/.env.$DEPLOYMENT_STAGE | |
- name: Deploy | |
run: | | |
stacks_str=${{ steps.inspect_stacks_from_commit_message.outputs.stacks_str }} | |
read -r -a stacks <<< $stacks_str | |
if [ ${#stacks[@]} -eq 0 ]; then | |
echo "Deploying all stacks to $DEPLOYMENT_STAGE" | |
yarn deploy --stage $DEPLOYMENT_STAGE | |
else | |
for stack in "${stacks[@]}"; do | |
echo "Deploying $stack to $DEPLOYMENT_STAGE" | |
yarn deploy $stack --stage $DEPLOYMENT_STAGE | |
done | |
fi |