-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-usable workflow for generating base-component-descriptor
"Base-Component-Descriptor(s)" have been proven to be beneficial for integrating OCM-Component-Descriptors into CICD-Pipelines. Implement a reusable workflow that will generate a base-component-descriptor to avoid boilerplate in downstream pipelines. This is a preliminary for enabling both a stand-alone `component-descriptor` workflow/action(s), as well as support for draft-release-pipelines (which can operate on base-component-descriptors).
- Loading branch information
Showing
2 changed files
with
188 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
name: Generate Base Component-Descriptor | ||
on: | ||
workflow_call: | ||
inputs: | ||
version: | ||
required: true | ||
type: string | ||
component-name: | ||
required: false | ||
type: string | ||
description: | | ||
Sets the Component-Name. If not passed, defaults to repository-URL | ||
ocm-repo: | ||
required: true | ||
type: string | ||
description: | | ||
the OCM-Repository the Component-Descriptor is intended to be published to | ||
commit-digest: | ||
required: false | ||
type: string | ||
description: | | ||
the commit-digest to use for declaring main source. If not passed, will default to | ||
current HEAD. Useful in conjunction with `capture-commit` / `import-commit`, if | ||
release-commit is created upfront. | ||
provider: | ||
required: false | ||
type: string | ||
default: SAP SE | ||
labels: | ||
required: false | ||
type: string | ||
description: | | ||
Labels to set for the component in YAML-form (caveat: need to quote). May either be a | ||
single object, or an array. | ||
Example: | ||
# single label | ||
name: cloud.gardener.cnudie/responsibles | ||
value: | ||
- type: githubTeam | ||
teamname: gardener/maintainers | ||
github_hostname: github.com | ||
# list of labels | ||
- name: label1 | ||
value: value1 | ||
- name: label2 | ||
value: value2 | ||
src-labels: | ||
required: false | ||
type: string | ||
description: | | ||
Labels to be set for main-source. Same syntax as for `labels` | ||
artefact-name: | ||
default: base-component-descriptor | ||
type: string | ||
description: | | ||
Base-Component-Descriptor is exposed both via output (component-descriptor) and as | ||
artefact. If needed, target-artefact-name can be configured through this input. | ||
jobs: | ||
base-component-descriptor: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
component-descriptor: ${{ steps.generate.outputs.component-descriptor }} | ||
artefact-name: ${{ steps.generate.outputs.artefact-name }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: install gardener-gha-libs | ||
uses: ./.github/actions/install-gardener-gha-libs | ||
- name: Generate Base-Component-Descriptor | ||
id: generate | ||
run: | | ||
set -eu | ||
host="$(echo ${{ github.server_url }} | cut -d / -f3)" | ||
if ${{ inputs.component-name || false }}; then | ||
component_name="${{inputs.component-name}}" | ||
else | ||
component_name="${host}/${{ github.repository }}" | ||
fi | ||
version="${{ inputs.version }}" | ||
ocm_repo="${{ inputs.ocm-repo }}" | ||
provider="${{ inputs.provider }}" | ||
if [ -n "${{ inputs.labels }}" ]; then | ||
labels="${{ inputs.labels }}" | ||
else | ||
labels="[]" | ||
fi | ||
echo "Initial Component-Descriptor:" | ||
python3 -m ocm create \ | ||
--name "${component_name}" \ | ||
--version "${version}" \ | ||
--ocm-repo "${ocm_repo}" \ | ||
--provider "${provider}" \ | ||
--label "${labels}" \ | ||
> component-descriptor.yaml | ||
cat component-descriptor.yaml | ||
echo "Adding main source:" | ||
set -x | ||
if [ -n "${{ inputs.commit-digest }}" ]; then | ||
commit="${{ inputs.commit-digest }}" | ||
else | ||
commit="${{ github.sha }}" | ||
fi | ||
if [ -n "${{ inputs.src-labels }}" ]; then | ||
src_labels="${{ inputs.src-labels }}" | ||
else | ||
src_labels='[]' | ||
fi | ||
classification_label="$(cat << EOF | ||
name: cloud.gardener/cicd/source | ||
value: | ||
repository-classification: main | ||
EOF | ||
)" | ||
cat << EOF | python3 -m ocm append source \ | ||
--label "${src_labels}" \ | ||
--label "${classification_label}" \ | ||
--file component-descriptor.yaml | ||
name: main-source | ||
version: ${version} | ||
type: git | ||
access: | ||
type: github | ||
repoUrl: ${host}/${{ github.repository }} | ||
commit: ${commit} | ||
ref: ${{ github.ref }} | ||
EOF | ||
echo "Component-Descriptor:" | ||
cat component-descriptor.yaml | ||
# XXX: TODO: honour .ci/component_descriptor-callback | ||
echo 'component-descriptor<<EOF' >> ${GITHUB_OUTPUT} | ||
cat component-descriptor.yaml >> ${GITHUB_OUTPUT} | ||
echo EOF >> ${GITHUB_OUTPUT} | ||
cat << EOF > ${GITHUB_STEP_SUMMARY} | ||
## Base OCM-Component-Descriptor | ||
\`\`\` | ||
$(cat component-descriptor.yaml) | ||
\`\`\` | ||
EOF | ||
- name: Upload Base-Component-Descriptor | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: ${{ inputs.artefact-name }} | ||
path: component-descriptor.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters