diff --git a/.github/workflows/test-validate-domain.yaml b/.github/workflows/test-validate-domain.yaml new file mode 100644 index 00000000..f17fb7f7 --- /dev/null +++ b/.github/workflows/test-validate-domain.yaml @@ -0,0 +1,18 @@ +name: test-validate-domain + +on: + pull_request: + paths: + - "actions/validate-domain/**" + +jobs: + validate-domain: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Test validate domain action + uses: ./actions/validate-domain + with: + chart-file: test/helm/Chart.yaml diff --git a/actions/validate-domain/README.md b/actions/validate-domain/README.md new file mode 100644 index 00000000..6273ea0d --- /dev/null +++ b/actions/validate-domain/README.md @@ -0,0 +1,32 @@ +# validate-domain + +Validate that a Helm chart (`Chart.yaml`) contains an `annotations.domain` value that is one of a configured set of allowed domains. + +## ✨ What It Does + +The action: +Checks if the `Chart.yaml` has the "domain" annotation and validates that the domain is in the domains list + +## Inputs + +| Name | Required | Default | Description | +|------|----------|---------|-------------| +| `chart-file` | no | `helm/Chart.yaml` | Path to the Helm chart file whose `annotations.domain` will be validated. | + +The set of allowed domains is constant (not configurable): + +``` +raster, vector, infra, 3d, app, dem, common +``` + +If you need to change or extend this list, update the action source or open a PR. + + +## 🚀 Usage + + +```yaml + - name: Validate domain + uses: MapColonies/shared-workflows/actions/validate-domain@v1 +``` + diff --git a/actions/validate-domain/action.yaml b/actions/validate-domain/action.yaml new file mode 100644 index 00000000..9c927fd9 --- /dev/null +++ b/actions/validate-domain/action.yaml @@ -0,0 +1,30 @@ +name: validate-domain +description: "Validate that helm/Chart.yaml contains annotations.domain with an allowed value" + +inputs: + chart-file: + description: "Path to Chart.yaml" + required: false + default: "helm/Chart.yaml" + +runs: + using: composite + steps: + - name: Read domain annotation from Chart.yaml + id: get_domain + uses: mikefarah/yq@v4.48.2 + with: + cmd: yq e '.annotations.domain' "${{ inputs.chart-file }}" + + - name: Validate domain + env: + ALLOWED_DOMAINS: "raster,vector,infra,3d,app,dem,common" + shell: bash + run: | + DOMAIN="${{ steps.get_domain.outputs.result }}" + IFS=',' read -ra ALLOWED <<< "${{ env.ALLOWED_DOMAINS }}" + + if ! printf "%s\n" "${ALLOWED[@]}" | grep -qx "$DOMAIN"; then + echo "Invalid domain: $DOMAIN" + exit 1 + fi diff --git a/release-please-config.json b/release-please-config.json index 64e155e3..9cf27734 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -68,6 +68,11 @@ "release-type": "simple", "package-name": "init-npm", "extra-files": ["README.md"] + }, + "actions/validate-domain": { + "release-type": "simple", + "package-name": "validate-domain", + "extra-files": ["README.md"] } } } diff --git a/test/helm/Chart.yaml b/test/helm/Chart.yaml index 93afb8dd..870366a4 100644 --- a/test/helm/Chart.yaml +++ b/test/helm/Chart.yaml @@ -1,5 +1,7 @@ apiVersion: v2 name: hello-world-chart +annotations: + domain: common description: A Helm chart for Kubernetes type: application version: 6.0.0