|
67 | 67 | test_image_tag: ${{ steps.vars.outputs.test_image_tag }} |
68 | 68 | alias_tag: ${{ steps.vars.outputs.alias_tag }} |
69 | 69 | clean_ref: ${{ steps.vars.outputs.clean_ref }} |
| 70 | + default_ref: ${{ steps.vars.outputs.default_ref }} |
70 | 71 | ngen_image_digest: ${{ steps.vars.outputs.ngen_image_digest }} |
71 | 72 | ngen_image_revision: ${{ steps.vars.outputs.ngen_image_revision }} |
| 73 | + ewts_revision: ${{ steps.vars.outputs.ewts_revision }} |
| 74 | + msw_mgr_revision: ${{ steps.vars.outputs.msw_mgr_revision }} |
72 | 75 | steps: |
73 | 76 | - name: Compute image vars |
74 | 77 | id: vars |
@@ -100,6 +103,18 @@ jobs: |
100 | 103 | CLEAN_REF=$(echo "$REAL_REF" | tr '[:upper:]' '[:lower:]' | sed 's/\//-/g') |
101 | 104 | SHORT_SHA="${REAL_SHA:0:7}" |
102 | 105 |
|
| 106 | + # default source-repo ref: follow the release-line branch we're building from |
| 107 | + # (development / ngwpc-candidate / ngwpc-release); tags and other branches fall |
| 108 | + # back to development. Override per source repo via the *_REF dispatch inputs. |
| 109 | + case "${GITHUB_REF_TYPE}:${GITHUB_REF_NAME}" in |
| 110 | + branch:development|branch:ngwpc-candidate|branch:ngwpc-release) |
| 111 | + DEFAULT_REF="$GITHUB_REF_NAME" ;; |
| 112 | + *) |
| 113 | + DEFAULT_REF="development" ;; |
| 114 | + esac |
| 115 | + # use an explicit *_REF input if provided, else DEFAULT_REF |
| 116 | + ref_or_default() { [ -n "$1" ] && echo "$1" || echo "$DEFAULT_REF"; } |
| 117 | +
|
103 | 118 | # logic for the tags: |
104 | 119 | # test_image_tag (commit short sha): used for the initial build and test |
105 | 120 | # alias_tag: used for final tagging on successful tests |
@@ -127,20 +142,40 @@ jobs: |
127 | 142 | # base image (ngen) metadata for Dockerfile labels |
128 | 143 | NGEN_IMAGE_TAG="${{ inputs.NGEN_IMAGE_TAG || 'latest' }}" |
129 | 144 | NGEN_IMAGE="ghcr.io/${ORG}/ngen:${NGEN_IMAGE_TAG}" |
130 | | - NGEN_INSPECT=$(skopeo inspect "docker://${NGEN_IMAGE}" 2>/dev/null || echo '{}') |
| 145 | + NGEN_INSPECT=$(skopeo inspect --override-os linux --override-arch amd64 "docker://${NGEN_IMAGE}" 2>/dev/null || echo '{}') |
131 | 146 | NGEN_IMAGE_DIGEST=$(echo "$NGEN_INSPECT" | jq -r '.Digest // "unknown"') |
132 | 147 | NGEN_IMAGE_REVISION=$(echo "$NGEN_INSPECT" | jq -r '.Labels["org.opencontainers.image.revision"] // "unknown"') |
133 | 148 |
|
| 149 | + # resolve each source repo's ref (branch/tag/SHA) to its commit SHA for revision labels |
| 150 | + resolve_sha() { |
| 151 | + local url="$1" ref="$2" out sha |
| 152 | + # a full 40-char SHA can't be looked up via ls-remote; use it directly |
| 153 | + if [[ "$ref" =~ ^[0-9a-f]{40}$ ]]; then echo "$ref"; return; fi |
| 154 | + out=$(git ls-remote "$url" "$ref" "refs/tags/${ref}^{}" 2>/dev/null) |
| 155 | + # prefer the dereferenced commit (^{}) for annotated tags; else first match |
| 156 | + sha=$(echo "$out" | grep '\^{}$' | head -n1 | cut -f1) |
| 157 | + [ -z "$sha" ] && sha=$(echo "$out" | head -n1 | cut -f1) |
| 158 | + echo "${sha:-unknown}" |
| 159 | + } |
| 160 | +
|
| 161 | + EWTS_REVISION=$(resolve_sha "https://github.com/${{ inputs.EWTS_ORG || github.repository_owner }}/nwm-ewts.git" "$(ref_or_default "${{ inputs.EWTS_REF }}")") |
| 162 | + MSW_MGR_REVISION=$(resolve_sha "https://github.com/${{ inputs.MSW_MGR_ORG || github.repository_owner }}/nwm-msw-mgr.git" "$(ref_or_default "${{ inputs.MSW_MGR_REF }}")") |
| 163 | +
|
134 | 164 | # save outputs |
135 | | - echo "org=${ORG}" >> "$GITHUB_OUTPUT" |
136 | | - echo "image_base=${IMAGE_BASE}" >> "$GITHUB_OUTPUT" |
137 | | - echo "test_image_tag=${TEST_TAG}" >> "$GITHUB_OUTPUT" |
138 | | - echo "alias_tag=${ALIAS}" >> "$GITHUB_OUTPUT" |
139 | | - echo "commit_sha=${REAL_SHA}" >> "$GITHUB_OUTPUT" |
140 | | - echo "commit_sha_short=${SHORT_SHA}" >> "$GITHUB_OUTPUT" |
141 | | - echo "clean_ref=${CLEAN_REF}" >> "$GITHUB_OUTPUT" |
142 | | - echo "ngen_image_digest=${NGEN_IMAGE_DIGEST}" >> "$GITHUB_OUTPUT" |
143 | | - echo "ngen_image_revision=${NGEN_IMAGE_REVISION}" >> "$GITHUB_OUTPUT" |
| 165 | + cat >> "$GITHUB_OUTPUT" <<EOF |
| 166 | + org=${ORG} |
| 167 | + image_base=${IMAGE_BASE} |
| 168 | + test_image_tag=${TEST_TAG} |
| 169 | + alias_tag=${ALIAS} |
| 170 | + commit_sha=${REAL_SHA} |
| 171 | + commit_sha_short=${SHORT_SHA} |
| 172 | + clean_ref=${CLEAN_REF} |
| 173 | + default_ref=${DEFAULT_REF} |
| 174 | + ngen_image_digest=${NGEN_IMAGE_DIGEST} |
| 175 | + ngen_image_revision=${NGEN_IMAGE_REVISION} |
| 176 | + ewts_revision=${EWTS_REVISION} |
| 177 | + msw_mgr_revision=${MSW_MGR_REVISION} |
| 178 | + EOF |
144 | 179 |
|
145 | 180 | # CodeQL scan |
146 | 181 | codeql-scan: |
@@ -202,9 +237,11 @@ jobs: |
202 | 237 | BASE_IMAGE_DIGEST=${{ needs.setup.outputs.ngen_image_digest }} |
203 | 238 | BASE_IMAGE_REVISION=${{ needs.setup.outputs.ngen_image_revision }} |
204 | 239 | EWTS_ORG=${{ inputs.EWTS_ORG || github.repository_owner }} |
205 | | - EWTS_REF=${{ inputs.EWTS_REF || 'development' }} |
| 240 | + EWTS_REF=${{ inputs.EWTS_REF || needs.setup.outputs.default_ref }} |
| 241 | + EWTS_REVISION=${{ needs.setup.outputs.ewts_revision }} |
206 | 242 | MSW_MGR_ORG=${{ inputs.MSW_MGR_ORG || github.repository_owner }} |
207 | | - MSW_MGR_REF=${{ inputs.MSW_MGR_REF || 'development' }} |
| 243 | + MSW_MGR_REF=${{ inputs.MSW_MGR_REF || needs.setup.outputs.default_ref }} |
| 244 | + MSW_MGR_REVISION=${{ needs.setup.outputs.msw_mgr_revision }} |
208 | 245 | IMAGE_SOURCE=https://github.com/${{ github.repository }} |
209 | 246 | IMAGE_VENDOR=${{ github.repository_owner }} |
210 | 247 | IMAGE_VERSION=${{ needs.setup.outputs.clean_ref }} |
|
0 commit comments