Revise local container checking #603
Workflow file for this run
This file contains hidden or 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: Lint, Test, and Build Backend | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| env: | |
| GO_VERSION: '1.26.2' | |
| SQLC_VERSION: '1.28.0' | |
| MOCKERY_VERSION: '3.7.0' | |
| jobs: | |
| Lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v7 | |
| - name: Setup go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Setup Sqlc | |
| uses: sqlc-dev/setup-sqlc@v5 | |
| with: | |
| sqlc-version: ${{ env.SQLC_VERSION }} | |
| - name: Setup mockery | |
| uses: brokeyourbike/go-mockery-action@v0 | |
| with: | |
| mockery-version: ${{ env.MOCKERY_VERSION }} | |
| - name: Build | |
| run: | | |
| go mod download | |
| make gen | |
| - name: Lint | |
| uses: golangci/golangci-lint-action@v9 | |
| with: | |
| version: v2.12 | |
| Test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v7 | |
| - name: Setup go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Setup Sqlc | |
| uses: sqlc-dev/setup-sqlc@v5 | |
| with: | |
| sqlc-version: ${{ env.SQLC_VERSION }} | |
| - name: Setup mockery | |
| uses: brokeyourbike/go-mockery-action@v0 | |
| with: | |
| mockery-version: ${{ env.MOCKERY_VERSION }} | |
| - name: Test | |
| run: make test | |
| Build: | |
| needs: Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v7 | |
| - name: Setup go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Setup Sqlc | |
| uses: sqlc-dev/setup-sqlc@v5 | |
| with: | |
| sqlc-version: ${{ env.SQLC_VERSION }} | |
| - name: Setup mockery | |
| uses: brokeyourbike/go-mockery-action@v0 | |
| with: | |
| mockery-version: ${{ env.MOCKERY_VERSION }} | |
| - name: Build | |
| run: | | |
| go mod download | |
| make gen | |
| env GOOS=linux go build -o bin/backend cmd/backend/main.go | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} | |
| password: ${{ secrets.DOCKER_REGISTRY_TOKEN }} | |
| - name: Build and Push Docker image | |
| uses: docker/build-push-action@v7 | |
| with: | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| push: true | |
| tags: | | |
| nycusdc/clustron-backend:pr-${{ github.event.number }} | |
| nycusdc/clustron-backend:${{ github.sha }} | |
| context: . | |
| Deploy: | |
| name: Deploy | |
| needs: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract PR body for webhook | |
| uses: NYCU-SDC/Extract-PRbody@V1.0 | |
| id: extract | |
| with: | |
| pr_body: ${{ github.event.pull_request.body }} | |
| - name: Process PR body for webhook | |
| run: | | |
| PR_TYPE=$(jq -Rs . << 'EOF' | |
| ${{ steps.extract.outputs.type_block }} | |
| EOF | |
| ) | |
| PR_PURPOSE=$(jq -Rs . << 'EOF' | |
| ${{ steps.extract.outputs.purpose_block }} | |
| EOF | |
| ) | |
| { | |
| echo "PR_TYPE=$PR_TYPE" | |
| echo "PR_PURPOSE=$PR_PURPOSE" | |
| } >> "$GITHUB_ENV" | |
| - name: Trigger n8n Snapshot Webhook | |
| run: | | |
| json=$(jq -n \ | |
| --arg title "Clustron" \ | |
| --arg repo "${{ github.repository }}" \ | |
| --arg branch "${{ github.head_ref || github.ref_name }}" \ | |
| --arg commit "${{ github.sha }}" \ | |
| --arg pr_number "${{ github.event.number }}" \ | |
| --arg pr_title "${{ github.event.pull_request.title }}" \ | |
| --arg pr_type "$PR_TYPE" \ | |
| --arg pr_purpose "$PR_PURPOSE" \ | |
| '{ | |
| source: { | |
| title: $title, | |
| repo: $repo, | |
| branch: $branch, | |
| commit: $commit, | |
| pr_number: $pr_number, | |
| pr_title: $pr_title, | |
| pr_type: $pr_type, | |
| pr_purpose: $pr_purpose | |
| }, | |
| method: "deploy", | |
| metadata: { | |
| environment: "snapshot", | |
| component: "backend" | |
| }, | |
| setup: { | |
| inject_secret: { | |
| enable: true, | |
| project: "clustron", | |
| environment: "snapshot", | |
| secrets: [ | |
| { | |
| path: "/google-oauth", | |
| secret_name: "CLIENT_ID", | |
| env_name: "GOOGLE_OAUTH_CLIENT_ID" | |
| }, | |
| { | |
| path: "/google-oauth", | |
| secret_name: "CLIENT_SECRET", | |
| env_name: "GOOGLE_OAUTH_CLIENT_SECRET" | |
| }, | |
| { | |
| path: "/nycu-oauth", | |
| secret_name: "CLIENT_ID", | |
| env_name: "NYCU_OAUTH_CLIENT_ID" | |
| }, | |
| { | |
| path: "/nycu-oauth", | |
| secret_name: "CLIENT_SECRET", | |
| env_name: "NYCU_OAUTH_CLIENT_SECRET" | |
| }, | |
| { | |
| "path": "/github-oauth", | |
| "secret_name": "CLIENT_ID", | |
| "env_name": "GITHUB_OAUTH_CLIENT_ID" | |
| }, | |
| { | |
| "path": "/github-oauth", | |
| "secret_name": "CLIENT_SECRET", | |
| "env_name": "GITHUB_OAUTH_CLIENT_SECRET" | |
| }, | |
| { | |
| path: "/", | |
| secret_name: "JWT_SECRET", | |
| env_name: "SECRET" | |
| }, | |
| { | |
| path: "/", | |
| secret_name: "OAUTH_PROXY_TOKEN", | |
| env_name: "OAUTH_PROXY_SECRET" | |
| }, | |
| { | |
| path: "/", | |
| secret_name: "SLURM_TOKEN_HELPER_URL", | |
| env_name: "SLURM_TOKEN_HELPER_URL" | |
| }, | |
| { | |
| path: "/", | |
| secret_name: "SLURM_RESTFUL_BASE_URL", | |
| env_name: "SLURM_RESTFUL_BASE_URL" | |
| } | |
| ] | |
| } | |
| }, | |
| post: { | |
| notify_discord: { | |
| enable: true, | |
| channel: "clustron-activity" | |
| }, | |
| setup_domain: { | |
| enable: true, | |
| title: "Endpoint", | |
| name: "api.pr-${{ github.event.pull_request.number }}.clustron.sdc.nycu.club", | |
| value: "default-eng-deploy:internal" | |
| } | |
| } | |
| }') | |
| echo "===== JSON to send =====" | |
| echo "$json" | |
| curl --location --request POST 'https://webhook.sdc.nycu.club/webhook/deploy' \ | |
| --header 'Content-Type: application/json' \ | |
| --header 'x-deploy-token: ${{ secrets.N8N_DEPLOY_TOKEN }}' \ | |
| --data "$json" |