Merge pull request #215 from CCIP-App/dependabot/npm_and_yarn/esbuild… #296
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: Deploy | |
on: | |
push: | |
branches: [main] | |
paths-ignore: | |
- 'docs/**' | |
- 'README.md' | |
repository_dispatch: | |
concurrency: deploy | |
env: | |
wranglerVersion: 3.98.0 | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- name: Set name suffix | |
run: | | |
if [ -z "$OVERRIDE_NAME_SUFFIX" ] | |
then | |
echo $GH_OWNER | awk '{ print "NAME_SUFFIX=" tolower($0) }' >> ${GITHUB_ENV} | |
else | |
echo $OVERRIDE_NAME_SUFFIX | awk '{ print "NAME_SUFFIX=" tolower($0) }' >> ${GITHUB_ENV} | |
fi | |
env: | |
GH_OWNER: ${{ github.repository_owner }} | |
OVERRIDE_NAME_SUFFIX: ${{ vars.OVERRIDE_NAME_SUFFIX }} | |
- uses: actions/checkout@v4 | |
- uses: hashicorp/setup-terraform@v2 | |
- name: Install package | |
run: | | |
sudo apt-get -y install jq | |
- name: Setup node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: 'yarn' | |
- name: Create D1 database | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: d1 create ccip-${{ env.NAME_SUFFIX }} | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
continue-on-error: true | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
# NOTE: v3 required sudo to run apt-get and not allow to append with pipe | |
- name: retrieve D1 database | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: d1 list --json | jq -r '.[] | select(.name == "ccip-${{ env.NAME_SUFFIX }}") | .uuid' | awk '{print "d1_id="$1}' >> $GITHUB_ENV | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
preCommands: | | |
echo "*** pre commands ***" | |
apt-get update && apt-get -y install jq | |
echo "******" | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
- name: migrate D1 database | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: d1 migrations apply ccip-${{ env.NAME_SUFFIX }} | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
preCommands: | | |
echo "*** pre commands ***" | |
sed -i "s/__DATABASE_NAME__/ccip-${{ env.NAME_SUFFIX }}/g" wrangler.toml | |
sed -i "s/__DATABASE_ID__/${{ env.d1_id }}/g" wrangler.toml | |
echo "******" | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
- name: retrieve Terraform state KV namespace | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: kv:namespace list | jq -r '.[] | select( .title == "ccip-terraform-${{ env.NAME_SUFFIX }}-state" ) | .id' | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
preCommands: | | |
echo "*** pre commands ***" | |
apt-get update && apt-get -y install jq | |
echo "******" | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
- name: Init | |
run: terraform init | |
working-directory: ./tf | |
- name: download Terraform state | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: kv:key get --namespace-id=${{ env.tfstate_kv }} terraform.tfstate > ./tf/terraform.tfstate | |
postCommands: | | |
echo "*** post commands ***" | |
chmod 777 ./tf/terraform.tfstate | |
echo "******" | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
if: ${{ env.tfstate_kv != '' }} | |
- name: Configure | |
run: terraform plan && terraform apply -auto-approve | |
working-directory: ./tf | |
env: | |
TF_VAR_cloudflare_account_id: ${{ secrets.CF_ACCOUNT_ID }} | |
TF_VAR_cloudflare_api_token: ${{ secrets.CF_API_TOKEN }} | |
TF_VAR_name_suffix: ${{ env.NAME_SUFFIX }} | |
TF_VAR_d1_id: ${{ env.d1_id }} | |
- name: retrieve Terraform state KV namespace | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: kv:namespace list | jq -r '.[] | select( .title == "ccip-terraform-${{ env.NAME_SUFFIX }}-state" ) | .id' | awk '{print "tfstate_kv="$1}' >> $GITHUB_ENV | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
preCommands: | | |
echo "*** pre commands ***" | |
apt-get update && apt-get -y install jq | |
echo "******" | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
if: ${{ env.tfstate_kv == '' }} | |
- name: store Terraform state | |
uses: cloudflare/[email protected] | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
command: kv:key put --namespace-id=${{ env.tfstate_kv }} terraform.tfstate --path=./tf/terraform.tfstate | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
env: | |
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }} | |
- name: Cleanup .wrangler | |
run: sudo rm -rf .wrangler | |
- name: Publish | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
wranglerVersion: ${{ env.wranglerVersion }} | |
apiToken: ${{ secrets.CF_API_TOKEN }} | |
accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
preCommands: | | |
echo "*** pre commands ***" | |
yarn | |
yarn build | |
echo "******" | |
command: pages deploy --project-name=ccip-${{ env.NAME_SUFFIX }} --commit-hash=${{ github.sha }} dist |