|
| 1 | +name: Selectively Build and Push to Artifact Registry |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["master"] |
| 6 | + |
| 7 | +env: |
| 8 | + PROJECT_ID: cs3219-400714 |
| 9 | + REGION: asia-southeast1 |
| 10 | + GAR_LOCATION: asia-southeast1-docker.pkg.dev/cs3219-400714/peerprep/ |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-push-artifact: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + build_status: ${{ steps.set_output.outputs.build_status }} |
| 17 | + steps: |
| 18 | + - name: "Checkout" |
| 19 | + uses: "actions/checkout@v3" |
| 20 | + |
| 21 | + - name: Detect Changes in Microservices |
| 22 | + id: changes |
| 23 | + uses: dorny/paths-filter@v2 |
| 24 | + with: |
| 25 | + filters: | |
| 26 | + frontend: |
| 27 | + - 'frontend/**' |
| 28 | + user_service: |
| 29 | + - 'user_service/**' |
| 30 | + question_service: |
| 31 | + - 'question_service/**' |
| 32 | + matching_service: |
| 33 | + - 'matching_service/**' |
| 34 | + collab_service: |
| 35 | + - 'collab_service/**' |
| 36 | + |
| 37 | + - name: 'Create env file' |
| 38 | + run: | |
| 39 | + echo "${{ secrets.ENV_FILE }}" > .env |
| 40 | + |
| 41 | + - name: "Set up google auth" |
| 42 | + id: auth |
| 43 | + uses: "google-github-actions/auth@v1" |
| 44 | + with: |
| 45 | + credentials_json: "${{ secrets.SERVICE_ACCOUNT_KEY }}" |
| 46 | + |
| 47 | + - name: "Set up Cloud SDK" |
| 48 | + uses: "google-github-actions/setup-gcloud@v1" |
| 49 | + |
| 50 | + - name: "Use gcloud CLI" |
| 51 | + run: "gcloud info" |
| 52 | + |
| 53 | + - name: "Docker auth" |
| 54 | + run: |- |
| 55 | + gcloud auth configure-docker ${{ env.REGION }}-docker.pkg.dev --quiet |
| 56 | +
|
| 57 | + - name: Determine Build Status |
| 58 | + id: set_output |
| 59 | + run: echo "::set-output name=build_status::false" |
| 60 | + |
| 61 | + - name: 1. Build and Push frontend |
| 62 | + if: steps.changes.outputs.frontend == 'true' |
| 63 | + run: | |
| 64 | + docker-compose build frontend |
| 65 | + docker-compose push frontend |
| 66 | + echo "::set-output name=build_status::true" |
| 67 | +
|
| 68 | + - name: 2. Build and Push question-service |
| 69 | + if: steps.changes.outputs.question_service == 'true' |
| 70 | + run: | |
| 71 | + docker-compose build question-service |
| 72 | + docker-compose push question-service |
| 73 | + echo "::set-output name=build_status::true" |
| 74 | +
|
| 75 | + - name: 3. Build and Push user-service |
| 76 | + if: steps.changes.outputs.user_service == 'true' |
| 77 | + run: | |
| 78 | + docker-compose build user-service |
| 79 | + docker-compose push user-service |
| 80 | + echo "::set-output name=build_status::true" |
| 81 | +
|
| 82 | + - name: 4. Build and Push matching-service |
| 83 | + if: steps.changes.outputs.matching_service == 'true' |
| 84 | + run: | |
| 85 | + docker-compose build matching-service |
| 86 | + docker-compose push matching-service |
| 87 | + echo "::set-output name=build_status::true" |
| 88 | +
|
| 89 | + - name: 5. Build and Push collab-service |
| 90 | + if: steps.changes.outputs.collab_service == 'true' |
| 91 | + run: | |
| 92 | + docker-compose build collab-service |
| 93 | + docker-compose push collab-service |
| 94 | + echo "::set-output name=build_status::true" |
0 commit comments