|
| 1 | +name: Test Fork CI |
| 2 | + |
| 3 | +permissions: write-all |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + ref_name: |
| 9 | + description: "Branch or tag to use (e.g., network-operator-test)" |
| 10 | + required: true |
| 11 | + ref_type: |
| 12 | + description: "Type of ref to use (tag or branch)" |
| 13 | + required: true |
| 14 | + distinct_id: |
| 15 | + description: "Unique identifier for the run" |
| 16 | + |
| 17 | +jobs: |
| 18 | + # this job is needed for the parent job to de able to detect workflow run id and later its status |
| 19 | + test: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: echo distinct ID ${{ inputs.distinct_id }} |
| 23 | + run: echo ${{ inputs.distinct_id }} |
| 24 | + |
| 25 | + create-test-environment: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + - if: inputs.ref_type == 'tag' |
| 30 | + name: Create release tag and branch |
| 31 | + run: | |
| 32 | + git tag ${{ inputs.ref_name }} |
| 33 | + git push origin ${{ inputs.ref_name }} -f |
| 34 | + # We need to cut the release branch from the 'network-operator' master branch |
| 35 | + git fetch origin master --depth 1 |
| 36 | + git checkout origin/master |
| 37 | + release_branch=$(echo ${{ inputs.ref_name }} | sed -E 's/^network-operator-([0-9]+\.[0-9]+).+/v\1.x/') # example: transforms "network-operator-25.1.0-beta.2" to "v25.1.x" |
| 38 | + git checkout -b $release_branch |
| 39 | + git push origin $release_branch -f |
| 40 | + echo BRANCH=$release_branch | tee -a $GITHUB_ENV |
| 41 | + echo TAG=${{ inputs.ref_name }} | tee -a $GITHUB_ENV |
| 42 | + - if: inputs.ref_type == 'branch' |
| 43 | + name: Create release branch |
| 44 | + run: | |
| 45 | + git checkout -b ${{ inputs.ref_name }} |
| 46 | + git push origin ${{ inputs.ref_name }} -f |
| 47 | + echo BRANCH=${{ inputs.ref_name }} | tee -a $GITHUB_ENV |
| 48 | + - name: Store branch and tag |
| 49 | + id: store-tag-branch |
| 50 | + run: | |
| 51 | + echo BRANCH=$BRANCH >> $GITHUB_OUTPUT |
| 52 | + echo TAG=$TAG >> $GITHUB_OUTPUT |
| 53 | + outputs: |
| 54 | + branch: ${{ steps.store-tag-branch.outputs.BRANCH }} |
| 55 | + tag: ${{ steps.store-tag-branch.outputs.TAG }} |
| 56 | + |
| 57 | + call-reusable-ci-fork-workflow: |
| 58 | + needs: create-test-environment |
| 59 | + uses: ./.github/workflows/fork-ci-reusable.yml |
| 60 | + with: |
| 61 | + registry-internal: ghcr.io/mellanox |
| 62 | + service-account-username: nvidia-ci-cd |
| 63 | + service-account-email: [email protected] |
| 64 | + components: '[{"name": "nicConfigurationOperator", "imageName": "cloud-orchestration-reusable-workflows", "Dockerfile": "Dockerfile.test"}, |
| 65 | + {"name": "nicConfigurationConfigDaemon", "imageName": "another-cloud-orchestration-reusable-workflows", "Dockerfile": "Dockerfile.another-test"}]' |
| 66 | + chart-name: node-feature-discovery |
| 67 | + chart-path: "charts-to-test/node-feature-discovery" |
| 68 | + exclude-chart-files: '["Chart.yaml", "new-file-to-exclude"]' |
| 69 | + ref-name: ${{ inputs.ref_name }} |
| 70 | + ref-type: ${{ inputs.ref_type }} |
| 71 | + network-operator-repo: reusable-release-workflows |
| 72 | + secrets: |
| 73 | + registry-username: ${{ github.repository_owner }} |
| 74 | + registry-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + cicd-gh-token: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + # TODO test that image was made with a new DOCKER_TAG from a specific branch |
| 78 | + validate-pr-with-updated-version-open: |
| 79 | + needs: call-reusable-ci-fork-workflow |
| 80 | + runs-on: ubuntu-latest |
| 81 | + env: |
| 82 | + GH_TOKEN: ${{ github.token }} |
| 83 | + steps: |
| 84 | + - name: Validate that a PR with updated versions was opened |
| 85 | + id: validate_pr_open |
| 86 | + run: | |
| 87 | + OUTPUT=$(gh pr list --repo ${{ github.repository }} --search="state:open in:title ${{ needs.call-reusable-ci-fork-workflow.outputs.docker-tag }}" --json headRefName,number) |
| 88 | +
|
| 89 | + # Validate that the output contains exactly one element |
| 90 | + if [ "$(echo "$OUTPUT" | jq 'length')" -eq 1 ]; then |
| 91 | + HEAD_REF_NAME=$(echo "$OUTPUT" | jq -r '.[0].headRefName') |
| 92 | + PR_NUMBER=$(echo "$OUTPUT" | jq -r '.[0].number') |
| 93 | + echo "head_ref_name=$HEAD_REF_NAME" >> $GITHUB_OUTPUT |
| 94 | + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 95 | + else |
| 96 | + echo "Error: Output does not contain exactly 1 element." >&2 |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | + shell: bash |
| 100 | + outputs: |
| 101 | + head-ref-name: ${{ steps.validate_pr_open.outputs.HEAD_REF_NAME }} |
| 102 | + pr-number: ${{ steps.validate_pr_open.outputs.PR_NUMBER }} |
| 103 | + |
| 104 | + validate-pr-changes: |
| 105 | + needs: |
| 106 | + - call-reusable-ci-fork-workflow |
| 107 | + - validate-pr-with-updated-version-open |
| 108 | + runs-on: ubuntu-latest |
| 109 | + steps: |
| 110 | + - uses: actions/checkout@v4 |
| 111 | + with: |
| 112 | + ref: ${{ needs.validate-pr-with-updated-version-open.outputs.head-ref-name }} |
| 113 | + - name: Verify version changes in PR |
| 114 | + env: |
| 115 | + DOCKER_TAG: ${{ needs.call-reusable-ci-fork-workflow.outputs.docker-tag }} |
| 116 | + # TODO make react on public and internal registries if needed |
| 117 | + DOCKER_REGISTRY: ghcr.io/mellanox |
| 118 | + RELEASE_FILE: hack/release.yaml |
| 119 | + run: | |
| 120 | + make check-release-build |
| 121 | +
|
| 122 | + echo "Validating changes in release.yaml..." |
| 123 | +
|
| 124 | + OPERATOR_VERSION=$(yq '.nicConfigurationOperator.version' $RELEASE_FILE) |
| 125 | + DAEMON_VERSION=$(yq '.nicConfigurationConfigDaemon.version' $RELEASE_FILE) |
| 126 | + OPERATOR_REPO=$(yq '.nicConfigurationOperator.repository' $RELEASE_FILE) |
| 127 | + DAEMON_REPO=$(yq '.nicConfigurationConfigDaemon.repository' $RELEASE_FILE) |
| 128 | +
|
| 129 | + echo "Found operator version $OPERATOR_VERSION and repo $OPERATOR_REPO, daemon version $DAEMON_VERSION and repo $DAEMON_REPO" |
| 130 | +
|
| 131 | + if [ "$OPERATOR_VERSION" != "$DOCKER_TAG" ]; then \ |
| 132 | + echo "Error: NicConfigurationOperator version is not set correctly in $RELEASE_FILE"; exit 1; \ |
| 133 | + fi |
| 134 | +
|
| 135 | + if [ "$DAEMON_VERSION" != "$DOCKER_TAG" ]; then \ |
| 136 | + echo "Error: NicConfigurationConfigDaemon version is not set correctly in $RELEASE_FILE"; exit 1; \ |
| 137 | + fi |
| 138 | +
|
| 139 | + if [ "$OPERATOR_REPO" != "$DOCKER_REGISTRY" ]; then \ |
| 140 | + echo "Error: NicConfigurationOperator repository is not set correctly in $RELEASE_FILE"; exit 1; \ |
| 141 | + fi |
| 142 | +
|
| 143 | + if [ "$DAEMON_REPO" != "$DOCKER_REGISTRY" ]; then \ |
| 144 | + echo "Error: NicConfigurationConfigDaemon repository is not set correctly in $RELEASE_FILE"; exit 1; \ |
| 145 | + fi |
| 146 | +
|
| 147 | + # TODO validate that the docker image was built from the requested branch |
| 148 | +
|
| 149 | + echo "Validating changes in the helm chart..." |
| 150 | +
|
| 151 | + PATH_TO_CHART="deployment/network-operator/charts/node-feature-discovery" |
| 152 | +
|
| 153 | + ls $PATH_TO_CHART |
| 154 | +
|
| 155 | + if [[ -f "$PATH_TO_CHART/new-file-to-exclude" ]]; then |
| 156 | + echo "Error: new-file-to-exclude should not have been copied to network-operator" >&2 |
| 157 | + exit 1 |
| 158 | + fi |
| 159 | +
|
| 160 | + if [[ ! -f "$PATH_TO_CHART/new-file-to-add" ]]; then |
| 161 | + echo "Error: new-file-to-add should have been copied to network-operator" >&2 |
| 162 | + exit 1 |
| 163 | + fi |
| 164 | +
|
| 165 | + if grep -Fxq "new content" $PATH_TO_CHART/Chart.yaml; then |
| 166 | + echo "Error: existing-file-to-exclude should not have been updated in the network-operator" >&2 |
| 167 | + exit 1 |
| 168 | + fi |
| 169 | +
|
| 170 | + if ! grep -Fxq "new content" $PATH_TO_CHART/crds/nfd-api-crds.yaml; then |
| 171 | + echo "Error: existing-file-to-change should have been updated in the network-operator" >&2 |
| 172 | + exit 1 |
| 173 | + fi |
| 174 | +
|
| 175 | + cleanup: |
| 176 | + if: always() |
| 177 | + env: |
| 178 | + GH_TOKEN: ${{ github.token }} |
| 179 | + needs: |
| 180 | + - create-test-environment |
| 181 | + - validate-pr-with-updated-version-open |
| 182 | + - validate-pr-changes |
| 183 | + runs-on: ubuntu-latest |
| 184 | + steps: |
| 185 | + - uses: actions/checkout@v4 |
| 186 | + - name: Delete all tags and branches that might have been created in the repo |
| 187 | + env: |
| 188 | + BRANCH: ${{ needs.create-test-environment.outputs.branch }} |
| 189 | + TAG: ${{ needs.create-test-environment.outputs.tag }} |
| 190 | + PR_BRANCH: ${{ needs.validate-pr-with-updated-version-open.outputs.head-ref-name }} |
| 191 | + PR_NUMBER: ${{ needs.validate-pr-with-updated-version-open.outputs.pr-number }} |
| 192 | + run: | |
| 193 | + if [ -n "$PR_NUMBER" ]; then |
| 194 | + echo "Closing PR #$PR_NUMBER..." |
| 195 | + gh pr close "$PR_NUMBER" |
| 196 | + fi |
| 197 | +
|
| 198 | + if [ -n "$PR_BRANCH" ]; then |
| 199 | + echo "Deleting pr branch $PR_BRANCH from origin..." |
| 200 | + git push origin --delete "$PR_BRANCH" |
| 201 | + fi |
| 202 | +
|
| 203 | + if [ -n "$BRANCH" ]; then |
| 204 | + echo "Deleting branch $BRANCH from origin..." |
| 205 | + git push origin --delete "$BRANCH" |
| 206 | + fi |
| 207 | +
|
| 208 | + if [ -n "$TAG" ]; then |
| 209 | + echo "Deleting tag $TAG from origin..." |
| 210 | + git push origin --delete refs/tags/$TAG |
| 211 | + fi |
0 commit comments