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

ci: update workflow for deploy based on tag. #485

Merged
merged 3 commits into from
Aug 7, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
name: release

name: Deploy GCP Testnet Bootnodes
on:
push:
branches:
- main
- test
- dev

paths-ignore:
- 'docs/**'
- '**.md'
- '.github/workflows/build.yaml'
- '.github/workflows/gh-release.yaml'
- '.github/workflows/publish-to-docs.yaml'
tags:
- 'v*' # This will match any tag that starts with 'v'

permissions:
id-token: write
Expand All @@ -22,49 +12,43 @@ jobs:
build-and-release:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref == 'refs/heads/test' && 'test' || 'dev' }}
name: "test" #will expand to other envs later, currently "test" deploys to the 5 GCP bootnodes
outputs:
environment: ${{ steps.set-env.outputs.environment }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Set Version
run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV

run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Build Binary
run: |
make build

- id: auth
uses: google-github-actions/auth@v2
with:
workload_identity_provider: projects/784882329213/locations/global/workloadIdentityPools/github-oidc-pool/providers/github-oidc-provider
service_account: gh-masa-oracle-${{ github.ref_name }}@masa-chain.iam.gserviceaccount.com

- name: Install Google Cloud SDK
uses: google-github-actions/setup-gcloud@v2
with:
version: 'latest'
project_id: ${{ vars.GCP_PROJECT_ID }}

- name: Upload Binary and config for contracts npm modules to GCP
run: |
BINARY_NAME=$(git rev-parse --short HEAD)
gsutil cp ./masa-node gs://${{ vars.GCP_BUCKET_NAME }}/$BINARY_NAME/masa-node
gsutil cp ./masa-node gs://${{ vars.GCP_BUCKET_NAME }}/masa-node
BINARY_NAME=${GITHUB_REF#refs/tags/}
gsutil cp ./bin/masa-node gs://${{ vars.GCP_BUCKET_NAME }}/$BINARY_NAME/masa-node
gsutil cp ./bin/masa-node gs://${{ vars.GCP_BUCKET_NAME }}/masa-node
gsutil cp ./contracts/* gs://${{ vars.GCP_BUCKET_NAME }}/$BINARY_NAME/
gsutil cp ./contracts/* gs://${{ vars.GCP_BUCKET_NAME }}/

- name: Set environment output
id: set-env
run: echo "::set-output name=environment::${{ github.ref_name }}"
run: echo "environment=test" >> $GITHUB_OUTPUT

deploy:
needs: build-and-release
Expand All @@ -77,18 +61,14 @@ jobs:
with:
workload_identity_provider: projects/784882329213/locations/global/workloadIdentityPools/github-oidc-pool/providers/github-oidc-provider
service_account: gh-masa-oracle-${{ github.ref_name }}@masa-chain.iam.gserviceaccount.com

- name: Update Instance Metadata
run: |
ENVIRONMENT="${{ github.ref_name }}"
ENVIRONMENT="production"
echo "Looking for instances with env metadata: $ENVIRONMENT"
INSTANCES=$(gcloud compute instances list --filter="metadata.items.ENV=$ENVIRONMENT" --format="get(name)")

echo "Found instances: $INSTANCES"

for INSTANCE in $INSTANCES; do
ZONE=$(gcloud compute instances list --filter="name=($INSTANCE)" --format="get(zone)" --limit=1)
echo "Updating instance: $INSTANCE in zone: $ZONE"
gcloud compute instances add-metadata $INSTANCE --metadata masa-oracle-redeploy=latest --zone=$(echo $ZONE | tr -d '\n')
gcloud compute instances add-metadata $INSTANCE --metadata masa-oracle-redeploy=${GITHUB_REF#refs/tags/} --zone=$(echo $ZONE | tr -d '\n')
done

Loading