|
| 1 | +--- |
| 2 | +name: Provide repository metadata |
| 3 | + |
| 4 | +on: # yamllint disable-line rule:truthy |
| 5 | + workflow_call: |
| 6 | + outputs: |
| 7 | + image-name: |
| 8 | + description: The name of the Docker image. |
| 9 | + value: ${{ jobs.output-repo-metadata.outputs.image-name }} |
| 10 | + image-platforms: |
| 11 | + description: The supported platforms for the Docker image. |
| 12 | + value: ${{ jobs.output-repo-metadata.outputs.image-platforms }} |
| 13 | + |
| 14 | +jobs: |
| 15 | + output-repo-metadata: |
| 16 | + name: Generate outputs for repository metadata |
| 17 | + outputs: |
| 18 | + image-name: ${{ steps.set-outputs.outputs.image-name }} |
| 19 | + image-platforms: ${{ steps.set-outputs.outputs.image-platforms }} |
| 20 | + permissions: {} |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Set outputs for repository metadata |
| 24 | + id: set-outputs |
| 25 | + run: | |
| 26 | + # Standard Python Libraries |
| 27 | + import json |
| 28 | + import os |
| 29 | + import sys |
| 30 | + from typing import Any, TypedDict |
| 31 | +
|
| 32 | +
|
| 33 | + class GhaOutput(TypedDict): |
| 34 | +
|
| 35 | + description: str |
| 36 | + name: str |
| 37 | + value: Any |
| 38 | +
|
| 39 | +
|
| 40 | + # Every output in this list must be configured as an output for the workflow. |
| 41 | + gha_outputs: list[GhaOutput] = [ |
| 42 | + { |
| 43 | + "description": "The name of the Docker image.", |
| 44 | + "name": "image-name", |
| 45 | + "value": "cisagov/postfix", |
| 46 | + }, |
| 47 | + { |
| 48 | + "description": "The supported platforms for the Docker image.", |
| 49 | + "name": "image-platforms", |
| 50 | + "value": [ |
| 51 | + # The platforms disabled below are not available for the current |
| 52 | + # base image (debian:bullseye-slim). Please see #60 for more |
| 53 | + # information. |
| 54 | + "linux/386", |
| 55 | + "linux/amd64", |
| 56 | + # "linux/arm/v6", |
| 57 | + "linux/arm/v7", |
| 58 | + "linux/arm64", |
| 59 | + # "linux/ppc64le", |
| 60 | + # "linux/riscv64", |
| 61 | + # "linux/s390x", |
| 62 | + ], |
| 63 | + }, |
| 64 | + ] |
| 65 | +
|
| 66 | + if os.getenv("GITHUB_OUTPUT") is None: |
| 67 | + print( |
| 68 | + "GITHUB_OUTPUT is not set. " |
| 69 | + "This script is intended to be run in a GitHub Actions environment." |
| 70 | + ) |
| 71 | + sys.exit(1) |
| 72 | +
|
| 73 | + with open(os.environ["GITHUB_OUTPUT"], "a") as gh_output: |
| 74 | + for output in gha_outputs: |
| 75 | + if any(isinstance(output["value"], t) for t in [list, dict]): |
| 76 | + output["value"] = json.dumps(output["value"]) |
| 77 | + gh_output.write(f"{output['name']}={output['value']}\n") |
| 78 | + shell: python3 {0} |
0 commit comments