From 4b9985c364a3378c01c5d67c10755e3872192335 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 4 Nov 2024 14:52:45 +0100 Subject: [PATCH 1/2] Add auto-merger support to mariadb. It is GitHub Action relevant issue. MariaDB code is untouched Signed-off-by: Petr "Stone" Hracek --- .github/auto-merge.yml | 1 + .github/workflows/auto-merge-on-demand.yml | 71 ++++++++++++++++++++++ .github/workflows/auto-merge.yml | 43 +++++++++++++ .github/workflows/pr-metadata.yml | 27 ++++++++ 4 files changed, 142 insertions(+) create mode 100644 .github/auto-merge.yml create mode 100644 .github/workflows/auto-merge-on-demand.yml create mode 100644 .github/workflows/auto-merge.yml create mode 100644 .github/workflows/pr-metadata.yml diff --git a/.github/auto-merge.yml b/.github/auto-merge.yml new file mode 100644 index 0000000..4aaecf6 --- /dev/null +++ b/.github/auto-merge.yml @@ -0,0 +1 @@ +target-branch: [] diff --git a/.github/workflows/auto-merge-on-demand.yml b/.github/workflows/auto-merge-on-demand.yml new file mode 100644 index 0000000..47003fd --- /dev/null +++ b/.github/workflows/auto-merge-on-demand.yml @@ -0,0 +1,71 @@ +name: Auto Merge Scheduled / On Demand +on: + schedule: + # Workflow runs every 45 minutes + - cron: '*/45 * * * *' + workflow_dispatch: + inputs: + pr-number: + description: 'Pull Request number/s ; when not provided, the workflow will run for all open PRs' + required: true + default: '0' + +permissions: + contents: read + +jobs: + # Get all open PRs + gather-pull-requests: + if: github.repository_owner == 'sclorg' + runs-on: ubuntu-latest + + outputs: + pr-numbers: ${{ steps.get-pr-numbers.outputs.result }} + pr-numbers-manual: ${{ steps.parse-manual-input.outputs.result }} + + steps: + - id: get-pr-numbers + if: inputs.pr-number == '0' + name: Get all open PRs + uses: actions/github-script@v7 + with: + # !FIXME: this is not working if there is more than 100 PRs opened + script: | + const { data: pullRequests } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + per_page: 100 + }); + return pullRequests.map(pr => pr.number); + + - id: parse-manual-input + if: inputs.pr-number != '0' + name: Parse manual input + run: | + # shellcheck disable=SC2086 + echo "result="[ ${{ inputs.pr-number }} ]"" >> $GITHUB_OUTPUT + shell: bash + + validate-pr: + name: 'Validation of Pull Request #${{ matrix.pr-number }}' + needs: [ gather-pull-requests ] + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + pr-number: ${{ inputs.pr-number == 0 && fromJSON(needs.gather-pull-requests.outputs.pr-numbers) || fromJSON(needs.gather-pull-requests.outputs.pr-numbers-manual) }} + + permissions: + # required for merging PRs + contents: write + # required for PR comments and setting labels + pull-requests: write + + steps: + - name: Auto Merge wrapper + uses: sclorg/auto-merge-wrapper@v1 + with: + pr-number: ${{ matrix.pr-number }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..f5a580e --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,43 @@ +name: Auto Merge +on: + workflow_run: + workflows: [ Gather Pull Request Metadata ] + types: + - completed + +permissions: + contents: read + +jobs: + download-metadata: + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + + outputs: + pr-metadata: ${{ steps.Artifact.outputs.pr-metadata-json }} + + steps: + - id: Artifact + name: Download Artifact + uses: redhat-plumbers-in-action/download-artifact@v1 + with: + name: pr-metadata + + auto-merge: + needs: [ download-metadata ] + runs-on: ubuntu-latest + + permissions: + # required for merging PRs + contents: write + # required for PR comments and setting labels + pull-requests: write + + steps: + - name: Auto Merge wrapper + uses: sclorg/auto-merge-wrapper@v1 + with: + pr-metadata: ${{ needs.download-metadata.outputs.pr-metadata }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-metadata.yml b/.github/workflows/pr-metadata.yml new file mode 100644 index 0000000..e4c77db --- /dev/null +++ b/.github/workflows/pr-metadata.yml @@ -0,0 +1,27 @@ +name: Gather Pull Request Metadata +on: + pull_request: + types: [ opened, reopened, synchronize ] + branches: [ master ] + +permissions: + contents: read + +jobs: + gather-metadata: + if: github.repository_owner == 'sclorg' + runs-on: ubuntu-latest + + steps: + - name: Repository checkout + uses: actions/checkout@v4 + + - id: Metadata + name: Gather Pull Request Metadata + uses: redhat-plumbers-in-action/gather-pull-request-metadata@v1 + + - name: Upload artifact with gathered metadata + uses: actions/upload-artifact@v4 + with: + name: pr-metadata + path: ${{ steps.Metadata.outputs.metadata-file }} From 07e41911d4e8e213e7eb00fec38627cae7b48eb4 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 5 Nov 2024 10:38:33 +0100 Subject: [PATCH 2/2] Rename tests to shared so the shared cluster is called at the end Signed-off-by: Petr "Stone" Hracek --- ...test_mariadb_template.py => test_mariadb_local_template.py} | 0 ...magestreams.py => test_mariadb_shared_helm_imagestreams.py} | 0 ...b_helm_template.py => test_mariadb_shared_helm_template.py} | 3 ++- 3 files changed, 2 insertions(+), 1 deletion(-) rename test/{test_mariadb_template.py => test_mariadb_local_template.py} (100%) rename test/{test_mariadb_helm_imagestreams.py => test_mariadb_shared_helm_imagestreams.py} (100%) rename test/{test_mariadb_helm_template.py => test_mariadb_shared_helm_template.py} (96%) diff --git a/test/test_mariadb_template.py b/test/test_mariadb_local_template.py similarity index 100% rename from test/test_mariadb_template.py rename to test/test_mariadb_local_template.py diff --git a/test/test_mariadb_helm_imagestreams.py b/test/test_mariadb_shared_helm_imagestreams.py similarity index 100% rename from test/test_mariadb_helm_imagestreams.py rename to test/test_mariadb_shared_helm_imagestreams.py diff --git a/test/test_mariadb_helm_template.py b/test/test_mariadb_shared_helm_template.py similarity index 96% rename from test/test_mariadb_helm_template.py rename to test/test_mariadb_shared_helm_template.py index d6d17be..a9606df 100644 --- a/test/test_mariadb_helm_template.py +++ b/test/test_mariadb_shared_helm_template.py @@ -13,11 +13,12 @@ class TestHelmMariaDBPersistent: def setup_method(self): package_name = "mariadb-persistent" path = test_dir - self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir, remote=True) + self.hc_api = HelmChartsAPI(path=path, package_name=package_name, tarball_dir=test_dir) self.hc_api.clone_helm_chart_repo( repo_url="https://github.com/sclorg/helm-charts", repo_name="helm-charts", subdir="charts/redhat" ) + def teardown_method(self): self.hc_api.delete_project()