From 039497a0a80c6c0deca6a21bc232a533396aced7 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Sat, 21 Oct 2023 17:19:39 +0200 Subject: [PATCH 1/3] =?UTF-8?q?ci:=20=F0=9F=91=B7=20modulize=20analyse=20s?= =?UTF-8?q?ervices=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Ruck --- .github/workflows/build-and-push.yaml | 13 +++++-- .github/workflows/get-changed-services.yaml | 38 +++++++++++++++++++++ .github/workflows/pull_request.yaml | 38 ++++----------------- .github/workflows/release.yaml | 38 +++------------------ 4 files changed, 60 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/get-changed-services.yaml diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index bd63f61b5..f97da592d 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -8,11 +8,17 @@ on: required: true default: '[]' type: string + secrets: + DOCKER_USERNAME: + description: 'Dockerhub Username' + required: true + DOCKER_PASSWORD: + description: 'Dockerhub Token' + required: true jobs: build-and-push: runs-on: ubuntu-latest - environment: docker if: ${{ inputs.changedPackages != '[]'}} strategy: fail-fast: false @@ -69,11 +75,12 @@ jobs: key: ${{ runner.os }}-multi-buildx-${{ github.sha }} restore-keys: | ${{ runner.os }}-multi-buildx + - name: Login to DockerHub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Read .node-version id: node_version diff --git a/.github/workflows/get-changed-services.yaml b/.github/workflows/get-changed-services.yaml new file mode 100644 index 000000000..8ba398d19 --- /dev/null +++ b/.github/workflows/get-changed-services.yaml @@ -0,0 +1,38 @@ +name: Get Changed Packages + +on: + workflow_call: + outputs: + CHANGED_PACKAGES: + value: ${{ jobs.analyse-changed-packages.outputs.changedPackages }} + +jobs: + analyse-changed-packages: + runs-on: ubuntu-latest + outputs: + changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + + - run: | + SINCE=$(git rev-list --tags --max-count=1) + echo SINCE=$SINCE >> $GITHUB_OUTPUT + echo SINCE=$SINCE + id: since + + - run: | + pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json + CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json) + echo CHANGED_PACKAGES=$CHANGED_PACKAGES >> $GITHUB_OUTPUT + echo CHANGED_PACKAGES=$CHANGED_PACKAGES + id: changed-packages + env: + SINCE: ${{ steps.since.outputs.SINCE }} diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 399d89d24..f654d686d 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -8,38 +8,14 @@ on: - 'master' jobs: - analyse-changed-packages: - runs-on: ubuntu-latest - outputs: - changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: pnpm/action-setup@v2 - with: - version: 8 - run_install: false - - - run: | - SINCE=$(git rev-list --tags --max-count=1) - echo SINCE=$SINCE >> $GITHUB_OUTPUT - echo SINCE=$SINCE - id: since - - - run: | - pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json - CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json) - echo CHANGED_PACKAGES=$CHANGED_PACKAGES >> $GITHUB_OUTPUT - echo CHANGED_PACKAGES=$CHANGED_PACKAGES - id: changed-packages - env: - SINCE: ${{ steps.since.outputs.SINCE }} + analyse-changed-services: + uses: ./.github/workflows/get-changed-services.yaml build-and-push: uses: ./.github/workflows/build-and-push.yaml - needs: analyse-changed-packages + needs: analyse-changed-services with: - changedPackages: ${{ needs.analyse-changed-packages.outputs.changedPackages }} + changedPackages: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES }} + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 253a77d5d..ed9d855b4 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -26,46 +26,18 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} jobs: - analyse-changed-packages: - runs-on: ubuntu-latest - outputs: - changed: ${{ steps.changed-packages.outputs.CHANGED }} - changedPackages: ${{ steps.changed-packages.outputs.CHANGED_PACKAGES }} - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: pnpm/action-setup@v2 - with: - version: 8 - run_install: false - - - run: | - SINCE=$(git rev-list --tags --max-count=1) - echo SINCE=$SINCE >> $GITHUB_OUTPUT - echo SINCE=$SINCE - id: since - - - run: | - pnpm list -r --json --filter "...[$SINCE]" | jq '[.[] | select(.private == false) | {name, path}]' > ./tmp.json - CHANGED_PACKAGES=$(jq '[.[] | .name]' ./tmp.json) - echo CHANGED_PACKAGES=$CHANGED_PACKAGES >> $GITHUB_OUTPUT - echo CHANGED_PACKAGES=$CHANGED_PACKAGES - id: changed-packages - env: - SINCE: ${{ steps.since.outputs.SINCE }} + analyse-changed-services: + uses: ./.github/workflows/get-changed-services.yaml release: - needs: [analyse-changed-packages] + needs: [analyse-changed-services] runs-on: ubuntu-latest - if: ${{ needs.analyse-changed-packages.outputs.changedPackages != '[]'}} + if: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES != '[]'}} strategy: fail-fast: false max-parallel: 1 matrix: - package: ${{fromJson(needs.analyse-changed-packages.outputs.changedPackages)}} + package: ${{fromJson(needs.analyse-changed-services.outputs.CHANGED_PACKAGES)}} steps: - name: Checkout Repo uses: actions/checkout@v4 From b6b4c94019788778d990d44af7afc1ee3d527680 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Sat, 21 Oct 2023 18:48:41 +0200 Subject: [PATCH 2/3] =?UTF-8?q?ci:=20=F0=9F=91=B7=20add=20action=20to=20re?= =?UTF-8?q?lease=20tagged=20services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-and-push-tagged.yaml | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/build-and-push-tagged.yaml diff --git a/.github/workflows/build-and-push-tagged.yaml b/.github/workflows/build-and-push-tagged.yaml new file mode 100644 index 000000000..58e85548d --- /dev/null +++ b/.github/workflows/build-and-push-tagged.yaml @@ -0,0 +1,30 @@ +name: Build and Push tagged + +on: + push: + tags: + - '*' + +jobs: + get-tagged-service: + runs-on: ubuntu-latest + outputs: + TAGGED_SERVICE: ${{ steps.get-tagged-service.outputs.TAGGED_SERVICE }} + steps: + # syntax: qr-code-handler@v1.0.8 + - name: Get tagged service + id: get-tagged-service + run: | + service=$(echo "${{ github.ref_name }}" | sed -n 's/^\(.*\)@v.*/\1/p') + serviceJSON=[\"$service\"] + echo "TAGGED_SERVICE=$serviceJSON" >> $GITHUB_OUTPUT + echo $serviceJSON + + build-and-push: + uses: ./.github/workflows/build-and-push.yaml + needs: get-tagged-service + with: + changedPackages: ${{ needs.get-tagged-service.outputs.TAGGED_SERVICE }} + secrets: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} From cc7405c6b8457539682ba0fbed219b2138d42e09 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Sat, 21 Oct 2023 18:52:46 +0200 Subject: [PATCH 3/3] =?UTF-8?q?ci:=20=F0=9F=91=B7=20checkout=20latest=20st?= =?UTF-8?q?ate=20for=20release=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ed9d855b4..a0570ecf1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -46,7 +46,10 @@ jobs: fetch-depth: 0 token: ${{ secrets.PAT }} # use PAT to being able to push to protected branch later on - - run: git checkout ${{ github.event.repository.default_branch }} + - name: Checkout latest default branch + run: | + git checkout ${{ github.event.repository.default_branch }} + git pull origin ${{ github.event.repository.default_branch }} if: ${{ contains(github.ref, github.event.repository.default_branch) }} - uses: pnpm/action-setup@v2