From bfc00ee04c906d19e2d875b9f2509888a68bcf8d Mon Sep 17 00:00:00 2001 From: Ezra Khairan Permana <48118327+reacto11mecha@users.noreply.github.com> Date: Sun, 21 Jul 2024 09:44:29 +0700 Subject: [PATCH] Push hanya pada saat git tag push dan package.json yang berubah (#56) * feat: menambahkan path-filter * fix: memperbaiki kurang tanda petik * fix: menambahkan action checkout * feat: menambahkan filter untuk mengecek apakah ada update dari masing masing package.json * fix: salah implementasi * feat: trigger github action hanya pada saat push tag saja * feat: menambahkan checkout ke baseline-docker * fix: bablas * feat: pindah ke step sendiri * chore: coba update web * fix: memperbaiki yang ke skip * chore: coba update web * feat: menambahkan fungsi rename versi * chore: coba update attendance * feat: pindah ke env * chore: update lagi * fix: salah tempat * fix: lagi lagi update * chore: rebuild lagi * chore: coba update processor * fix: kelebihan pulak * fix: biasaw * chore: coba up lagi * fix: jangan lupa titik koma * fix: semoga bener * fix: dikit lagi * fix: kok ga ada * chore: update (huft) * chore: update lagi (huft**2) * feat: menambahkan fungsionalitas push ke repo docker * fix: ubah pake manual * fix * fix * fix * fix: tanpa kurawal * fix: pindah jadi newline * feat: menambahkan fungsi push * feat: persiapan commit --- .github/workflows/build-docker.yml | 102 +++++++++++++++++++++++---- apps/clients/attendance/package.json | 2 +- apps/processor/package.json | 1 + apps/web/package.json | 2 +- 4 files changed, 93 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index d472c0c..b3e5d3f 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -2,17 +2,41 @@ name: Docker Image Build CI on: push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" branches: - main jobs: - web: - if: github.repository == 'sora-vp/baseline' + changes: + runs-on: ubuntu-latest + permissions: + pull-requests: read + outputs: + web: ${{ steps.filter.outputs.web }} + processor: ${{ steps.filter.outputs.processor }} + attendance: ${{ steps.filter.outputs.attendance }} + chooser: ${{ steps.filter.outputs.chooser }} + steps: + - uses: actions/checkout@v4 + - uses: dorny/paths-filter@v3 + id: filter + with: + base: HEAD + filters: | + web: 'apps/web/package.json' + processor: 'apps/processor/package.json' + attendance: 'apps/clients/attendance/package.json' + chooser: 'apps/clients/chooser/package.json' + + web: + needs: changes + if: github.repository == 'sora-vp/baseline' && needs.changes.outputs.web == 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -32,12 +56,12 @@ jobs: tags: ${{ secrets.DOCKERHUB_USERNAME }}/sora-baseline-web:${{ github.ref_name }} processor: - if: github.repository == 'sora-vp/baseline' - + needs: changes + if: github.repository == 'sora-vp/baseline' && needs.changes.outputs.processor == 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -57,12 +81,12 @@ jobs: tags: ${{ secrets.DOCKERHUB_USERNAME }}/sora-baseline-processor:${{ github.ref_name }} client-attendance: - if: github.repository == 'sora-vp/baseline' - + needs: changes + if: github.repository == 'sora-vp/baseline' && needs.changes.outputs.attendance == 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -82,12 +106,12 @@ jobs: tags: ${{ secrets.DOCKERHUB_USERNAME }}/sora-baseline-client-attendance:${{ github.ref_name }} client-chooser: - if: github.repository == 'sora-vp/baseline' - + needs: changes + if: github.repository == 'sora-vp/baseline' && needs.changes.outputs.chooser == 'true' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -105,3 +129,57 @@ jobs: file: "./apps/clients/chooser/Dockerfile" push: true tags: ${{ secrets.DOCKERHUB_USERNAME }}/sora-baseline-client-chooser:${{ github.ref_name }} + + update-docker-compose-repo: + needs: [web, processor, client-attendance, client-chooser] + if: | + always() + && (contains(needs.web.result, 'success') || contains(needs.processor.result, 'success') || contains(needs.client-attendance.result, 'success') || contains(needs.client-chooser.result, 'success')) + && !contains(needs.*.result, 'failure') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.BASIC_DOCKER_CONFIG_REPO_PAT }} + repository: sora-vp/baseline-docker + + - name: setup git config + run: | + git config --global user.name "github-actions" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Rename version + env: + WEB_UPDATE: ${{ needs.web.result }} + PROCESSOR_UPDATE: ${{ needs.processor.result }} + ATTENDANCE_UPDATE: ${{ needs.client-attendance.result }} + CHOOSER_UPDATE: ${{ needs.client-chooser.result }} + REF_NAME: ${{ github.ref_name }} + run: | + echo "WEB_UPDATE: $WEB_UPDATE" + echo "PROCESSOR_UPDATE: $PROCESSOR_UPDATE" + echo "ATTENDANCE_UPDATE: $ATTENDANCE_UPDATE" + echo "CHOOSER_UPDATE: $CHOOSER_UPDATE" + + if [ "$WEB_UPDATE" == "success" ]; then + sed -i 's/rmecha\/sora-baseline-web:[^ ]*/rmecha\/sora-baseline-web:'"$REF_NAME"'/' docker-compose.yml + fi + if [ "$PROCESSOR_UPDATE" == "success" ]; then + sed -i 's/rmecha\/sora-baseline-processor:[^ ]*/rmecha\/sora-baseline-processor:'"$REF_NAME"'/' docker-compose.yml + fi + if [ "$ATTENDANCE_UPDATE" == "success" ]; then + sed -i 's/rmecha\/sora-baseline-client-attendance:[^ ]*/rmecha\/sora-baseline-client-attendance:'"$REF_NAME"'/' docker-compose.yml + fi + if [ "$CHOOSER_UPDATE" == "success" ]; then + sed -i 's/rmecha\/sora-baseline-client-chooser:[^ ]*/rmecha\/sora-baseline-client-chooser:'"$REF_NAME"'/' docker-compose.yml + fi + + - name: Commit changes + env: + REF_NAME: ${{ github.ref_name }} + GITHUB_SHA: ${{ github.sha }} + run: | + git commit -am "bot-update: update $REF_NAME" -m "Cek commit -> https://github.com/sora-vp/baseline/commit/$GITHUB_SHA" + + - name: Push 🚀 + run: git push origin main diff --git a/apps/clients/attendance/package.json b/apps/clients/attendance/package.json index 60fb0c7..a49188c 100644 --- a/apps/clients/attendance/package.json +++ b/apps/clients/attendance/package.json @@ -1,7 +1,7 @@ { "name": "@sora-vp/client-attendance", "private": true, - "version": "2.3.1", + "version": "2.3.0", "type": "module", "scripts": { "build": "yarn with-env vite build", diff --git a/apps/processor/package.json b/apps/processor/package.json index 992200b..5776ee7 100644 --- a/apps/processor/package.json +++ b/apps/processor/package.json @@ -1,5 +1,6 @@ { "name": "@sora-vp/processor", + "version": "2.3.1", "private": true, "type": "module", "main": "dist/index.js", diff --git a/apps/web/package.json b/apps/web/package.json index 2087c41..7d7aba0 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,6 +1,6 @@ { "name": "@sora-vp/web", - "version": "0.1.0", + "version": "0.1.3", "private": true, "type": "module", "scripts": {