From 9997240832af0a3cedc02c2da2593e0b75296f4c Mon Sep 17 00:00:00 2001 From: Andrea Sorbini Date: Sat, 20 Apr 2024 05:19:27 -0700 Subject: [PATCH] Test PR process (#3) --- .github/workflows/_ci_build.yml | 5 ++-- .github/workflows/deb_release.yml | 3 +++ .github/workflows/pull_request.yml | 6 ++--- .github/workflows/pull_request_closed.yml | 16 ++++++++++-- .github/workflows/release_cleanup.yml | 16 ++++++++++-- .github/workflows_pyconfig/__init__.py | 3 +++ .github/workflows_pyconfig/settings.py | 2 ++ .github/workflows_pyconfig/settings.yml | 4 +-- .../workflows_pyconfig/workflows/ci_build.py | 2 +- .../workflows/pull_request.py | 7 +++++- .../workflows/release_summary.py | 25 ++++++++++--------- README.md | 15 ----------- 12 files changed, 64 insertions(+), 40 deletions(-) diff --git a/.github/workflows/_ci_build.yml b/.github/workflows/_ci_build.yml index eec6cbb..8436b60 100644 --- a/.github/workflows/_ci_build.yml +++ b/.github/workflows/_ci_build.yml @@ -38,7 +38,7 @@ jobs: config: runs-on: ubuntu-latest outputs: - CI_RUNNER: ${{ steps.config.outputs.RUNNER }} + CI_RUNNER: ${{ steps.config.outputs.CI_RUNNER }} CI_TESTER_IMAGE: ${{ steps.config.outputs.CI_TESTER_IMAGE }} LOCAL_TESTER_IMAGE: ${{ steps.config.outputs.LOCAL_TESTER_IMAGE }} LOCAL_TESTER_RESULTS: ${{ steps.config.outputs.LOCAL_TESTER_RESULTS }} @@ -70,7 +70,8 @@ jobs: LOGIN_DOCKERHUB = cfg.dyn.ci.login_dockerhub LOGIN_GITHUB = cfg.dyn.ci.login_github TEST_DATE = cfg.dyn.test_date - """) + """, + inputs="""${{ toJson(inputs) }}""") - name: Validate code run: | diff --git a/.github/workflows/deb_release.yml b/.github/workflows/deb_release.yml index 7252840..792c42f 100644 --- a/.github/workflows/deb_release.yml +++ b/.github/workflows/deb_release.yml @@ -22,6 +22,7 @@ jobs: config: runs-on: ubuntu-latest outputs: + DEB_ENABLED: ${{steps.config.outputs.DEB_ENABLED}} DEB_BASE_IMAGES: ${{steps.config.outputs.DEB_BASE_IMAGES}} DEB_BUILD_ARCHITECTURES: ${{steps.config.outputs.DEB_BUILD_ARCHITECTURES}} DEB_ARTIFACTS_PREFIX: ${{steps.config.outputs.DEB_ARTIFACTS_PREFIX}} @@ -45,10 +46,12 @@ jobs: DEB_BASE_IMAGES = cfg.dyn.debian.base_images_matrix DEB_BUILD_ARCHITECTURES = cfg.dyn.debian.build_architectures_matrix DEB_ARTIFACTS_PREFIX = cfg.debian.artifacts_prefix + DEB_ENABLED = cfg.dyn.debian.enabled """) build-packages: needs: config + if: needs.config.outputs.DEB_ENABLED strategy: matrix: base-image: ${{ fromJson(needs.config.outputs.DEB_BASE_IMAGES ) }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ce3fac9..5d796c2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -37,7 +37,7 @@ jobs: BASIC_VALIDATION_BUILD_PLATFORMS: ${{ steps.config.outputs.BASIC_VALIDATION_BUILD_PLATFORMS }} BASIC_VALIDATION_BASE_IMAGES: ${{ steps.config.outputs.BASIC_VALIDATION_BASE_IMAGES }} DEB_VALIDATION_BASE_IMAGES: ${{ steps.config.outputs.DEB_VALIDATION_BASE_IMAGES }} - DEB_VALIDATION_BUILD_PLATFORMS: ${{ steps.config.outputs.DEB_VALIDATION_BUILD_PLATFORMS }} + DEB_VALIDATION_BUILD_ARCHITECTURES: ${{ steps.config.outputs.DEB_VALIDATION_BUILD_ARCHITECTURES }} FULL_VALIDATION_BASE_IMAGES: ${{ steps.config.outputs.FULL_VALIDATION_BASE_IMAGES }} FULL_VALIDATION_BUILD_PLATFORMS: ${{ steps.config.outputs.FULL_VALIDATION_BUILD_PLATFORMS }} VALIDATE_BASIC: ${{ steps.config.outputs.VALIDATE_BASIC }} @@ -98,11 +98,11 @@ jobs: if: ${{ needs.check-trigger.outputs.VALIDATE_DEB }} strategy: matrix: - build-platform: ${{ fromJson(needs.check-trigger.outputs.DEB_VALIDATION_BUILD_PLATFORMS) }} + build-architecture: ${{ fromJson(needs.check-trigger.outputs.DEB_VALIDATION_BUILD_ARCHITECTURES) }} base-image: ${{ fromJson(needs.check-trigger.outputs.DEB_VALIDATION_BASE_IMAGES) }} uses: ./.github/workflows/_deb_build.yml secrets: inherit with: base-image: ${{ matrix.base-image }} - build-platform: ${{ matrix.build-platform }} + build-architecture: ${{ matrix.build-architecture }} diff --git a/.github/workflows/pull_request_closed.yml b/.github/workflows/pull_request_closed.yml index 3bea2c1..731c944 100644 --- a/.github/workflows/pull_request_closed.yml +++ b/.github/workflows/pull_request_closed.yml @@ -27,7 +27,6 @@ permissions: env: CLONE_DIR: src/repo - ADMIN_IMAGE: ghcr.io/${{ github.repository }}-admin:latest jobs: cleanup_jobs: @@ -42,6 +41,19 @@ jobs: with: path: ${{ env.CLONE_DIR }} submodules: true + + - name: Configure workflow + id: config + shell: python + run: | + import sys + sys.path.insert(0, "${{ env.CLONE_DIR }}/.github") + from workflows_pyconfig import configure + configure( + github="""${{ toJson(github) }}""", + outputs="""\ + ADMIN_IMAGE = cfg.ci.admin_image + """) - name: Log in to GitHub uses: docker/login-action@v3 @@ -56,7 +68,7 @@ jobs: -v $(pwd):/workspace \ -e GH_TOKEN=${GH_TOKEN} \ -w /workspace \ - ${ADMIN_IMAGE} \ + ${{steps.config.outputs.ADMIN_IMAGE}} \ ${{ env.CLONE_DIR }}/scripts/ci-admin \ -c ${{ github.run_id }} \ pr-closed \ diff --git a/.github/workflows/release_cleanup.yml b/.github/workflows/release_cleanup.yml index 7020f53..e1cd3d1 100644 --- a/.github/workflows/release_cleanup.yml +++ b/.github/workflows/release_cleanup.yml @@ -19,7 +19,6 @@ permissions: env: CLONE_DIR: src/repo - ADMIN_IMAGE: ghcr.io/${{ github.repository }}-admin:latest jobs: cleanup_jobs: @@ -32,13 +31,26 @@ jobs: path: ${{ env.CLONE_DIR }} submodules: true + - name: Configure workflow + id: config + shell: python + run: | + import sys + sys.path.insert(0, "${{ env.CLONE_DIR }}/.github") + from workflows_pyconfig import configure + configure( + github="""${{ toJson(github) }}""", + outputs="""\ + ADMIN_IMAGE = cfg.ci.admin_image + """) + - name: "Clean up workflow runs" run: | docker run --rm \ -v $(pwd):/workspace \ -e GH_TOKEN=${GH_TOKEN} \ -w /workspace \ - ${ADMIN_IMAGE} \ + ${{steps.config.outputs.ADMIN_IMAGE}} \ ${{ env.CLONE_DIR }}/scripts/ci-admin \ -c ${{ github.run_id }} \ nightly-cleanup \ diff --git a/.github/workflows_pyconfig/__init__.py b/.github/workflows_pyconfig/__init__.py index b2f443a..c39baa9 100644 --- a/.github/workflows_pyconfig/__init__.py +++ b/.github/workflows_pyconfig/__init__.py @@ -30,6 +30,9 @@ def _dict_to_tuple(key: str, val: dict) -> NamedTuple: fields = {} for k, v in val.items(): + if k.startswith("_"): + # field unsupported by namedtuple + continue if isinstance(v, dict): v = _dict_to_tuple(k, v) k = k.replace("-", "_").replace("/", "_") diff --git a/.github/workflows_pyconfig/settings.py b/.github/workflows_pyconfig/settings.py index c144708..d255bc0 100644 --- a/.github/workflows_pyconfig/settings.py +++ b/.github/workflows_pyconfig/settings.py @@ -126,6 +126,7 @@ def settings(cfg: NamedTuple, github: NamedTuple) -> dict: ] ) + debian_enabled = (clone_dir / "debian" / "control").is_file() debian_base_images_matrix = json.dumps(cfg.debian.base_images) debian_build_architectures_matrix = json.dumps(cfg.debian.build_architectures) debian_registries = _extract_registries( @@ -168,6 +169,7 @@ def settings(cfg: NamedTuple, github: NamedTuple) -> dict: "debian": { "base_images_matrix": debian_base_images_matrix, "build_architectures_matrix": debian_build_architectures_matrix, + "enabled": debian_enabled, "login_dockerhub": "dockerhub" in debian_registries, "login_github": "github" in debian_registries, }, diff --git a/.github/workflows_pyconfig/settings.yml b/.github/workflows_pyconfig/settings.yml index f4f2ad2..11d6c1d 100644 --- a/.github/workflows_pyconfig/settings.yml +++ b/.github/workflows_pyconfig/settings.yml @@ -47,8 +47,8 @@ pull_request: deb: base_images: - ubuntu:22.04 - build_platforms: - - linux/amd64 + build_architectures: + - amd64 ############################################################################# # Release settings diff --git a/.github/workflows_pyconfig/workflows/ci_build.py b/.github/workflows_pyconfig/workflows/ci_build.py index 241a832..eb3b592 100644 --- a/.github/workflows_pyconfig/workflows/ci_build.py +++ b/.github/workflows_pyconfig/workflows/ci_build.py @@ -21,7 +21,7 @@ def configure(cfg: NamedTuple, github: NamedTuple, inputs: NamedTuple) -> dict: runner = json.dumps(getattr(cfg.ci.runners, inputs.build_platform.replace("/", "_"))) repo = github.repository.split("/")[-1] - build_platform_label = cfg.dyn.build.platform.replace("/", "-") + build_platform_label = inputs.build_platform.replace("/", "-") base_image_tag = inputs.base_image.replace(":", "-") ci_tester_image = f"{cfg.ci.ci_tester_repo}:{base_image_tag}" diff --git a/.github/workflows_pyconfig/workflows/pull_request.py b/.github/workflows_pyconfig/workflows/pull_request.py index e6db30e..0f5e93a 100644 --- a/.github/workflows_pyconfig/workflows/pull_request.py +++ b/.github/workflows_pyconfig/workflows/pull_request.py @@ -96,6 +96,9 @@ def configure(cfg: NamedTuple, github: NamedTuple, inputs: NamedTuple) -> dict: ) result_basic = review_state != "approved" + # Debian testing requires a debian package. + result_deb = result_deb and (clone_dir / "debian" / "control").is_file() + print(f"PR {pr_no} configuration: basic={result_basic}, full={result_full}, deb={result_deb}") return { @@ -104,7 +107,9 @@ def configure(cfg: NamedTuple, github: NamedTuple, inputs: NamedTuple) -> dict: cfg.pull_request.validation.basic.build_platforms ), "DEB_VALIDATION_BASE_IMAGES": json.dumps(cfg.pull_request.validation.deb.base_images), - "DEB_VALIDATION_BUILD_PLATFORMS": json.dumps(cfg.pull_request.validation.deb.build_platforms), + "DEB_VALIDATION_BUILD_ARCHITECTURES": json.dumps( + cfg.pull_request.validation.deb.build_architectures + ), "FULL_VALIDATION_BASE_IMAGES": json.dumps(cfg.pull_request.validation.full.base_images), "FULL_VALIDATION_BUILD_PLATFORMS": json.dumps(cfg.pull_request.validation.full.build_platforms), "VALIDATE_FULL": result_full, diff --git a/.github/workflows_pyconfig/workflows/release_summary.py b/.github/workflows_pyconfig/workflows/release_summary.py index 7f77c17..06a1a30 100644 --- a/.github/workflows_pyconfig/workflows/release_summary.py +++ b/.github/workflows_pyconfig/workflows/release_summary.py @@ -72,18 +72,6 @@ def _deb_pkg_link(pkg: Path) -> str: return ( f"# {summary_title}" "\n" - "## Configuration" - "\n" - f"| Property | Value |" - "\n" - f"|----------|-------|" - "\n" - f"| **CI Settings** | {settings_link} |" - "\n" - f"| **Commit** | [`{github.sha}`]({repo_url}/tree/{github.sha}) |" - "\n" - f"| **GitHub Release** | {release_page} |" - "\n" "\n" "## Artifacts" "\n" @@ -99,4 +87,17 @@ def _deb_pkg_link(pkg: Path) -> str: f"| **Debian Packages** | {deb_packages_list} |" "\n" "\n" + "## Configuration" + "\n" + f"| Property | Value |" + "\n" + f"|----------|-------|" + "\n" + "\n" + f"| **CI Settings** | {settings_link} |" + "\n" + f"| **Commit** | [`{github.sha}`]({repo_url}/tree/{github.sha}) |" + "\n" + f"| **GitHub Release** | {release_page} |" + "\n" ) diff --git a/README.md b/README.md index 3cb3554..85656ac 100644 --- a/README.md +++ b/README.md @@ -108,21 +108,6 @@ The guide assumes that the repository will be owned by a GitHub organization (of which you are an administrator). Some adjustments might be required to use it for a personal repository. -### Required tools - -1. Clone this repository locally: - - ```sh - git clone https://github.com/mentalsmash/ref-project-debdocker - ``` - - Optionally, export the clone's location for easier reference when - following this guide: - - ```sh - export REF_PROJECT=$(pwd)/ref-project-docker - ``` - ### Repository Initialization 1. Create your repository (e.g. `my-org/my-repo`) if it doesn't already exist.