|
| 1 | +name: OCM |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + ocm_version: |
| 6 | + description: ocm-cli version to install |
| 7 | + required: false |
| 8 | + type: string |
| 9 | + default: "0.38.0" |
| 10 | + oci_registry: |
| 11 | + description: OCI registry namespace target (without OCIRegistry:: prefix) |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + default: "" |
| 15 | + chart_path: |
| 16 | + description: Optional local Helm chart path |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: "charts/audit-log-poc" |
| 20 | + constructor_path: |
| 21 | + description: Optional OCM constructor template path |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + default: "ocm/component-constructor.yaml" |
| 25 | + secrets: |
| 26 | + GHCR_TOKEN: |
| 27 | + required: false |
| 28 | + |
| 29 | +jobs: |
| 30 | + ocm: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Install tools |
| 42 | + shell: bash |
| 43 | + run: | |
| 44 | + set -euxo pipefail |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y jq |
| 47 | + YQ_VERSION="v4.44.5" |
| 48 | + sudo curl -fsSL -o /usr/local/bin/yq "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64" |
| 49 | + sudo chmod +x /usr/local/bin/yq |
| 50 | +
|
| 51 | + - name: Setup ocm-cli |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + set -euxo pipefail |
| 55 | + VERSION="${{ inputs.ocm_version }}" |
| 56 | + ARCHIVE_FILE="ocm-${VERSION}-linux-amd64.tar.gz" |
| 57 | + URL="https://github.com/open-component-model/ocm/releases/download/v${VERSION}/${ARCHIVE_FILE}" |
| 58 | + echo "Installing ocm-cli version v${VERSION} from ${URL}" |
| 59 | + curl -fsSL -o ocm-cli.tgz "${URL}" |
| 60 | + sudo tar --overwrite -xvzf ocm-cli.tgz -C /usr/local/bin |
| 61 | + sudo chmod a+x /usr/local/bin/ocm |
| 62 | + ocm version |
| 63 | +
|
| 64 | + - name: Setup helm |
| 65 | + uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0 |
| 66 | + with: |
| 67 | + version: v3.17.3 |
| 68 | + |
| 69 | + - name: Write .ocmconfig |
| 70 | + shell: bash |
| 71 | + env: |
| 72 | + OCM_USERNAME: ${{ github.actor }} |
| 73 | + GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + run: | |
| 76 | + set -euxo pipefail |
| 77 | + OCM_PASSWORD="${GHCR_TOKEN:-$GITHUB_TOKEN}" |
| 78 | + cat <<EOF > "${HOME}/.ocmconfig" |
| 79 | + type: generic.config.ocm.software/v1 |
| 80 | + configurations: |
| 81 | + - type: credentials.config.ocm.software |
| 82 | + consumers: |
| 83 | + - identity: |
| 84 | + type: OCIRegistry |
| 85 | + scheme: https |
| 86 | + hostname: ghcr.io |
| 87 | + credentials: |
| 88 | + - type: Credentials |
| 89 | + properties: |
| 90 | + username: ${OCM_USERNAME} |
| 91 | + password: ${OCM_PASSWORD} |
| 92 | + EOF |
| 93 | +
|
| 94 | + - name: Build OCM transport archive |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + set -euxo pipefail |
| 98 | + rm -f ocm/transport.ctf |
| 99 | + mkdir -p ocm |
| 100 | +
|
| 101 | + if [[ -f "${{ inputs.constructor_path }}" && -f "${{ inputs.chart_path }}/Chart.yaml" ]]; then |
| 102 | + echo "Detected constructor and chart, using templated Option-A flow" |
| 103 | + CHART_VERSION="$(yq -r '.version' "${{ inputs.chart_path }}/Chart.yaml")" |
| 104 | + APP_VERSION="$(yq -r '.appVersion // .version' "${{ inputs.chart_path }}/Chart.yaml")" |
| 105 | + PROVIDER="${{ github.repository_owner }}" |
| 106 | + COMPONENT_NAME="${{ github.repository_owner }}/audit-log-poc-for-otel" |
| 107 | + if [[ -f "${{ inputs.chart_path }}/values.yaml" ]]; then |
| 108 | + PRIMARY_IMAGE="$(yq -r '.image.registry + "/" + .image.repository + ":" + .image.tag' "${{ inputs.chart_path }}/values.yaml" 2>/dev/null || true)" |
| 109 | + else |
| 110 | + PRIMARY_IMAGE="" |
| 111 | + fi |
| 112 | + helm package "${{ inputs.chart_path }}" |
| 113 | + ocm add componentversions --create --templater=go --file=ocm/transport.ctf "${{ inputs.constructor_path }}" -- \ |
| 114 | + COMPONENT_NAME="${COMPONENT_NAME}" \ |
| 115 | + PROVIDER="${PROVIDER}" \ |
| 116 | + CHART_VERSION="${CHART_VERSION}" \ |
| 117 | + APP_VERSION="${APP_VERSION}" \ |
| 118 | + PRIMARY_IMAGE="${PRIMARY_IMAGE}" |
| 119 | + else |
| 120 | + echo "No local chart constructor flow detected, using showroom/ocm descriptors" |
| 121 | + shopt -s nullglob |
| 122 | + files=(showroom/ocm/*.yaml) |
| 123 | + if [[ ${#files[@]} -eq 0 ]]; then |
| 124 | + echo "No OCM descriptor files found under showroom/ocm/*.yaml" |
| 125 | + exit 1 |
| 126 | + fi |
| 127 | + for file in "${files[@]}"; do |
| 128 | + echo "Adding component from ${file}" |
| 129 | + done |
| 130 | + ocm add componentversions --create --file ocm/transport.ctf "${files[@]}" |
| 131 | + fi |
| 132 | +
|
| 133 | + - name: Push OCM artifact to OCI |
| 134 | + shell: bash |
| 135 | + run: | |
| 136 | + set -euxo pipefail |
| 137 | + if [[ -n "${{ inputs.oci_registry }}" ]]; then |
| 138 | + OCI_REGISTRY="${{ inputs.oci_registry }}" |
| 139 | + else |
| 140 | + OCI_REGISTRY="ghcr.io/${{ github.repository_owner }}" |
| 141 | + fi |
| 142 | + echo "Pushing OCM transport archive to ${OCI_REGISTRY}" |
| 143 | + ocm transfer ctf ./ocm/transport.ctf "OCIRegistry::${OCI_REGISTRY}" |
0 commit comments