Skip to content

Merge pull request #33 from sourcifyeth/staging #76

Merge pull request #33 from sourcifyeth/staging

Merge pull request #33 from sourcifyeth/staging #76

Workflow file for this run

name: Release on Google Bucket
on:
push:
branches:
- main
- staging
jobs:
release:
runs-on: ubuntu-latest
environment:
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: "auth staging"
if: github.ref == 'refs/heads/staging'
uses: "google-github-actions/auth@v2"
with:
workload_identity_provider: "projects/1019539084286/locations/global/workloadIdentityPools/github/providers/sourcify"
service_account: "sourcify-staging-ui-deployer@sourcify-project.iam.gserviceaccount.com"
- name: "auth main"
if: github.ref == 'refs/heads/main'
uses: "google-github-actions/auth@v2"
with:
workload_identity_provider: "projects/1019539084286/locations/global/workloadIdentityPools/github/providers/sourcify"
service_account: "sourcify-production-ui@sourcify-project.iam.gserviceaccount.com"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "22.4.0"
- name: Install dependencies
run: npm install
- name: Copy .env.build.staging to .env
if: github.ref == 'refs/heads/staging'
run: cp .env.build.staging .env
- name: Copy .env.build.main to .env
if: github.ref == 'refs/heads/main'
run: cp .env.build.main .env
- name: Build
env:
REACT_APP_OPENROUTER_API_KEY: ${{ secrets.REACT_APP_OPENROUTER_API_KEY }}
run: npm run build
- name: "setup-gcloud"
uses: "google-github-actions/setup-gcloud@v2"
- name: Clear Staging bucket (preserve stats.json and manifest.json)
if: github.ref == 'refs/heads/staging'
run: |
# Create temporary directory to backup files
mkdir -p temp_backup
# Backup the files we want to preserve
gsutil cp gs://sourcify-staging-ui-bucket/static/stats.json temp_backup/ 2>/dev/null || echo "stats.json not found, skipping backup"
gsutil cp gs://sourcify-staging-ui-bucket/static/manifest.json temp_backup/ 2>/dev/null || echo "manifest.json not found, skipping backup"
# Clear the bucket
gsutil -m rm gs://sourcify-staging-ui-bucket/** || true
# Restore the preserved files
if [ -f temp_backup/stats.json ]; then
gsutil cp temp_backup/stats.json gs://sourcify-staging-ui-bucket/static/
fi
if [ -f temp_backup/manifest.json ]; then
gsutil cp temp_backup/manifest.json gs://sourcify-staging-ui-bucket/static/
fi
# Clean up temporary directory
rm -rf temp_backup
- name: Clear Main bucket (preserve stats.json and manifest.json)
if: github.ref == 'refs/heads/main'
run: |
# Create temporary directory to backup files
mkdir -p temp_backup
# Backup the files we want to preserve
gsutil cp gs://sourcify-ui-bucket/static/stats.json temp_backup/ 2>/dev/null || echo "stats.json not found, skipping backup"
gsutil cp gs://sourcify-ui-bucket/static/manifest.json temp_backup/ 2>/dev/null || echo "manifest.json not found, skipping backup"
# Clear the bucket
gsutil -m rm gs://sourcify-ui-bucket/** || true
# Restore the preserved files
if [ -f temp_backup/stats.json ]; then
gsutil cp temp_backup/stats.json gs://sourcify-ui-bucket/static/
fi
if [ -f temp_backup/manifest.json ]; then
gsutil cp temp_backup/manifest.json gs://sourcify-ui-bucket/static/
fi
# Clean up temporary directory
rm -rf temp_backup
- name: Upload files to Staging bucket
if: github.ref == 'refs/heads/staging'
uses: google-github-actions/upload-cloud-storage@v2
with:
path: "build"
destination: "sourcify-staging-ui-bucket"
parent: false
glob: "**/*"
- name: Upload files to Main bucket
if: github.ref == 'refs/heads/main'
uses: google-github-actions/upload-cloud-storage@v2
with:
path: "build"
destination: "sourcify-ui-bucket"
parent: false
glob: "**/*"