|
| 1 | +--- |
| 2 | +name: Run integration tests in Testing Farm |
| 3 | +on: |
| 4 | + issue_comment: |
| 5 | + types: |
| 6 | + - created |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + # This is required for the ability to create/update the Pull request status |
| 10 | + statuses: write |
| 11 | +jobs: |
| 12 | + prepare_vars: |
| 13 | + name: Get info from role and PR to determine if and how to test |
| 14 | + # The concurrency key is used to prevent multiple workflows from running at the same time |
| 15 | + concurrency: |
| 16 | + # group name contains reponame-pr_num to allow simualteneous runs in different PRs |
| 17 | + group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number }} |
| 18 | + cancel-in-progress: true |
| 19 | + # Let's schedule tests only on user request. NOT automatically. |
| 20 | + # Only repository owner or member can schedule tests |
| 21 | + if: | |
| 22 | + github.event.issue.pull_request |
| 23 | + && contains(github.event.comment.body, '[citest]') |
| 24 | + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR", "CONTRIBUTOR"]'), github.event.comment.author_association) |
| 25 | + || contains('systemroller', github.event.comment.user.login)) |
| 26 | + runs-on: ubuntu-latest |
| 27 | + outputs: |
| 28 | + supported_platforms: ${{ steps.supported_platforms.outputs.supported_platforms }} |
| 29 | + head_sha: ${{ steps.head_sha.outputs.head_sha }} |
| 30 | + memory: ${{ steps.memory.outputs.memory }} |
| 31 | + steps: |
| 32 | + - name: Dump github context |
| 33 | + run: echo "$GITHUB_CONTEXT" |
| 34 | + shell: bash |
| 35 | + env: |
| 36 | + GITHUB_CONTEXT: ${{ toJson(github) }} |
| 37 | + |
| 38 | + - name: Checkout repo |
| 39 | + uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Get head sha of the PR |
| 42 | + id: head_sha |
| 43 | + run: | |
| 44 | + head_sha=$(gh api "repos/$REPO/pulls/$PR_NO" --jq '.head.sha') |
| 45 | + echo "head_sha=$head_sha" >> $GITHUB_OUTPUT |
| 46 | + env: |
| 47 | + REPO: ${{ github.repository }} |
| 48 | + PR_NO: ${{ github.event.issue.number }} |
| 49 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + |
| 51 | + - name: Checkout PR |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + ref: ${{ steps.head_sha.outputs.head_sha }} |
| 55 | + |
| 56 | + - name: Get memory |
| 57 | + id: memory |
| 58 | + run: | |
| 59 | + if [ -d tests/provision.fmf ]; then |
| 60 | + memory=$(grep -rPo ' m: \K(.*)' tests/provision.fmf) |
| 61 | + fi |
| 62 | + if [ -n "$memory" ]; then |
| 63 | + echo "memory=$memory" >> $GITHUB_OUTPUT |
| 64 | + else |
| 65 | + echo "memory=2048" >> $GITHUB_OUTPUT |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Get supported platforms |
| 69 | + id: supported_platforms |
| 70 | + run: | |
| 71 | + supported_platforms="" |
| 72 | + meta_main=meta/main.yml |
| 73 | + # All Fedora are supported, add latest Fedora versions to supported_platforms |
| 74 | + if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi fedora$; then |
| 75 | + supported_platforms+=" Fedora-39" |
| 76 | + supported_platforms+=" Fedora-40" |
| 77 | + fi |
| 78 | + # Specific Fedora versions supported |
| 79 | + if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qiP 'fedora\d+$'; then |
| 80 | + for fedora_ver in $(yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -iPo 'fedora\K(\d+$)'); do |
| 81 | + supported_platforms+=" Fedora-$fedora_ver" |
| 82 | + done |
| 83 | + fi |
| 84 | + if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi el7; then |
| 85 | + supported_platforms+=" CentOS-7-latest" |
| 86 | + fi |
| 87 | + for ver in 8 9 10; do |
| 88 | + if yq '.galaxy_info.galaxy_tags[]' "$meta_main" | grep -qi el"$ver"; then |
| 89 | + supported_platforms+=" CentOS-Stream-$ver" |
| 90 | + fi |
| 91 | + done |
| 92 | + echo "supported_platforms=$supported_platforms" >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + testing-farm: |
| 95 | + name: ${{ matrix.platform }}/ansible-${{ matrix.ansible_version }} |
| 96 | + needs: prepare_vars |
| 97 | + strategy: |
| 98 | + fail-fast: false |
| 99 | + matrix: |
| 100 | + include: |
| 101 | + - platform: Fedora-39 |
| 102 | + ansible_version: 2.17 |
| 103 | + - platform: Fedora-40 |
| 104 | + ansible_version: 2.17 |
| 105 | + - platform: CentOS-7-latest |
| 106 | + ansible_version: 2.9 |
| 107 | + - platform: CentOS-Stream-8 |
| 108 | + ansible_version: 2.9 |
| 109 | + # On CentOS-Stream-8, latest supported Ansible is 2.16 |
| 110 | + - platform: CentOS-Stream-8 |
| 111 | + ansible_version: 2.16 |
| 112 | + - platform: CentOS-Stream-9 |
| 113 | + ansible_version: 2.17 |
| 114 | + - platform: CentOS-Stream-10 |
| 115 | + ansible_version: 2.17 |
| 116 | + runs-on: ubuntu-latest |
| 117 | + env: |
| 118 | + ARTIFACTS_DIR_NAME: "tf_${{ github.event.repository.name }}-${{ github.event.issue.number }}_\ |
| 119 | + ${{ matrix.platform }}-${{ matrix.ansible_version }}_\ |
| 120 | + ${{ needs.prepare_vars.outputs.datetime }}/artifacts" |
| 121 | + ARTIFACT_TARGET_DIR: /srv/pub/alt/${{ vars.LINUXSYSTEMROLES_USER }}/logs |
| 122 | + steps: |
| 123 | + - name: Set variables with DATETIME and artifact location |
| 124 | + id: set_vars |
| 125 | + run: | |
| 126 | + printf -v DATETIME '%(%Y%m%d-%H%M%S)T' -1 |
| 127 | + ARTIFACTS_DIR_NAME="tf_${{ github.event.repository.name }}-${{ github.event.issue.number }}_\ |
| 128 | + ${{ matrix.platform }}-${{ matrix.ansible_version }}_$DATETIME/artifacts" |
| 129 | + ARTIFACTS_TARGET_DIR=/srv/pub/alt/${{ vars.LINUXSYSTEMROLES_USER }}/logs |
| 130 | + ARTIFACTS_DIR=$ARTIFACTS_TARGET_DIR/$ARTIFACTS_DIR_NAME |
| 131 | + ARTIFACTS_URL=https://dl.fedoraproject.org/pub/alt/${{ vars.LINUXSYSTEMROLES_USER }}/logs/$ARTIFACTS_DIR_NAME |
| 132 | + echo "DATETIME=$DATETIME" >> $GITHUB_OUTPUT |
| 133 | + echo "ARTIFACTS_DIR=$ARTIFACTS_DIR" >> $GITHUB_OUTPUT |
| 134 | + echo "ARTIFACTS_URL=$ARTIFACTS_URL" >> $GITHUB_OUTPUT |
| 135 | +
|
| 136 | + - name: Set commit status as pending |
| 137 | + if: contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform) |
| 138 | + uses: myrotvorets/set-commit-status-action@master |
| 139 | + with: |
| 140 | + sha: ${{ needs.prepare_vars.outputs.head_sha }} |
| 141 | + status: pending |
| 142 | + context: ${{ matrix.platform }}|ansible-${{ matrix.ansible_version }} |
| 143 | + description: Test started |
| 144 | + targetUrl: "" |
| 145 | + |
| 146 | + - name: Set commit status as success with a description that platform is skipped |
| 147 | + if: "!contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform)" |
| 148 | + uses: myrotvorets/set-commit-status-action@master |
| 149 | + with: |
| 150 | + sha: ${{ needs.prepare_vars.outputs.head_sha }} |
| 151 | + status: success |
| 152 | + context: ${{ matrix.platform }}|ansible-${{ matrix.ansible_version }} |
| 153 | + description: The role does not support this platform. Skipping. |
| 154 | + targetUrl: "" |
| 155 | + |
| 156 | + - name: Run test in testing farm |
| 157 | + uses: sclorg/testing-farm-as-github-action@v3 |
| 158 | + if: contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform) |
| 159 | + with: |
| 160 | + git_url: https://github.com/linux-system-roles/tft-tests |
| 161 | + git_ref: main |
| 162 | + pipeline_settings: '{ "type": "tmt-multihost" }' |
| 163 | + environment_settings: '{ "provisioning": { "tags": { "BusinessUnit": "system_roles" } } }' |
| 164 | + # Keeping ARTIFACTS_URL at the bottom makes the link in logs clickable |
| 165 | + variables: "ANSIBLE_VER=${{ matrix.ansible_version }};\ |
| 166 | + REPO_NAME=${{ github.event.repository.name }};\ |
| 167 | + GITHUB_ORG=${{ github.repository_owner }};\ |
| 168 | + PR_NUM=${{ github.event.issue.number }};\ |
| 169 | + ARTIFACTS_DIR=${{ steps.set_vars.outputs.ARTIFACTS_DIR }};\ |
| 170 | + TEST_LOCAL_CHANGES=false;\ |
| 171 | + LINUXSYSTEMROLES_USER=${{ vars.LINUXSYSTEMROLES_USER }};\ |
| 172 | + ARTIFACTS_URL=${{ steps.set_vars.outputs.ARTIFACTS_URL }}" |
| 173 | + # Note that LINUXSYSTEMROLES_SSH_KEY must be single-line, TF doesn't read multi-line variables fine. |
| 174 | + secrets: "LINUXSYSTEMROLES_DOMAIN=${{ secrets.LINUXSYSTEMROLES_DOMAIN }};\ |
| 175 | + LINUXSYSTEMROLES_SSH_KEY=${{ secrets.LINUXSYSTEMROLES_SSH_KEY }}" |
| 176 | + compose: ${{ matrix.platform }} |
| 177 | + # There are two blockers for using public ranch: |
| 178 | + # 1. multihost is not supported in public https://github.com/teemtee/tmt/issues/2620 |
| 179 | + # 2. Security issue that leaks long secrets - Jira TFT-2698 |
| 180 | + tf_scope: private |
| 181 | + api_key: ${{ secrets.TF_API_KEY_RH }} |
| 182 | + update_pull_request_status: false |
| 183 | + tmt_hardware: '{ "memory": ">= ${{ needs.prepare_vars.outputs.memory }} MB" }' |
| 184 | + tmt_plan_filter: "tag:general,postgresql" |
| 185 | + |
| 186 | + - name: Set final commit status |
| 187 | + uses: myrotvorets/set-commit-status-action@master |
| 188 | + if: always() && contains(needs.prepare_vars.outputs.supported_platforms, matrix.platform) |
| 189 | + with: |
| 190 | + sha: ${{ needs.prepare_vars.outputs.head_sha }} |
| 191 | + status: ${{ job.status }} |
| 192 | + context: ${{ matrix.platform }}|ansible-${{ matrix.ansible_version }} |
| 193 | + description: Test finished |
| 194 | + targetUrl: ${{ steps.set_vars.outputs.ARTIFACTS_URL }} |
0 commit comments