fix workflow to build binary with VERSION from git (#466) #244
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: release | |
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' | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build-and-release: | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.ref == 'refs/heads/main' && 'main' || github.ref == 'refs/heads/test' && 'test' || 'dev' }} | |
outputs: | |
environment: ${{ steps.set-env.outputs.environment }} | |
steps: | |
- uses: actions/checkout@v4 | |
- 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 | |
- name: Build Binary | |
run: | | |
echo "Building with version: ${{ env.VERSION }}" | |
go build -v -ldflags "-X github.com/masa-finance/masa-oracle/pkg/config.Version=${{ env.VERSION }}" -o masa-node ./cmd/masa-node | |
- 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 | |
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 }}" | |
deploy: | |
needs: build-and-release | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ needs.build-and-release.outputs.environment }} | |
steps: | |
- 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: Update Instance Metadata | |
run: | | |
ENVIRONMENT="${{ github.ref_name }}" | |
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') | |
done | |