Skip to content

Commit

Permalink
Test PR process (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
asorbini authored Apr 20, 2024
1 parent 7a9b902 commit 9997240
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/_ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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: |
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deb_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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 ) }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}

16 changes: 14 additions & 2 deletions .github/workflows/pull_request_closed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ permissions:

env:
CLONE_DIR: src/repo
ADMIN_IMAGE: ghcr.io/${{ github.repository }}-admin:latest

jobs:
cleanup_jobs:
Expand All @@ -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
Expand All @@ -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 \
Expand Down
16 changes: 14 additions & 2 deletions .github/workflows/release_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ permissions:

env:
CLONE_DIR: src/repo
ADMIN_IMAGE: ghcr.io/${{ github.repository }}-admin:latest

jobs:
cleanup_jobs:
Expand All @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows_pyconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/", "_")
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows_pyconfig/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows_pyconfig/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pull_request:
deb:
base_images:
- ubuntu:22.04
build_platforms:
- linux/amd64
build_architectures:
- amd64

#############################################################################
# Release settings
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows_pyconfig/workflows/ci_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows_pyconfig/workflows/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
25 changes: 13 additions & 12 deletions .github/workflows_pyconfig/workflows/release_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9997240

Please sign in to comment.