diff --git a/inventory/group_vars/active_roles.yml b/inventory/group_vars/active_roles.yml index 82def90..c8dbd0d 100644 --- a/inventory/group_vars/active_roles.yml +++ b/inventory/group_vars/active_roles.yml @@ -49,6 +49,7 @@ absent_files: - .github/actions/custom-woke-action - .github/actions - .commitlintrc.js + - .github/workflows/shellcheck.yml # some roles have shellcheck tests that are not shellcheck roles github_org: linux-system-roles github_url_prefix: "git@github.com:" default_ansible_lint: diff --git a/playbooks/role_templates/ha_cluster/.github/workflows/python-unit-test.yml b/playbooks/role_templates/ha_cluster/.github/workflows/python-unit-test.yml index c92445c..a458846 100644 --- a/playbooks/role_templates/ha_cluster/.github/workflows/python-unit-test.yml +++ b/playbooks/role_templates/ha_cluster/.github/workflows/python-unit-test.yml @@ -3,6 +3,13 @@ name: Python Unit Tests on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -14,11 +21,43 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: permissions: contents: read + pull-requests: read jobs: python: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_python-unit-test]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_python-unit-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_python-unit-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_python-unit-test') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) strategy: matrix: include: @@ -99,10 +138,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: checkout PR uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Install platform dependencies, python, tox, tox-lsr run: | diff --git a/playbooks/templates/.github/workflows/ansible-lint.yml b/playbooks/templates/.github/workflows/ansible-lint.yml index 69cdea4..21560f3 100644 --- a/playbooks/templates/.github/workflows/ansible-lint.yml +++ b/playbooks/templates/.github/workflows/ansible-lint.yml @@ -2,6 +2,13 @@ name: Ansible Lint on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -16,11 +23,43 @@ env: LSR_ROLE2COLL_NAME: {{ lsr_name }} permissions: contents: read + pull-requests: read jobs: ansible_lint: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_ansible-lint]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-lint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-lint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_ansible-lint') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest strategy: fail-fast: false @@ -38,10 +77,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Install tox, tox-lsr run: | diff --git a/playbooks/templates/.github/workflows/ansible-managed-var-comment.yml b/playbooks/templates/.github/workflows/ansible-managed-var-comment.yml index c53b741..10ad21f 100644 --- a/playbooks/templates/.github/workflows/ansible-managed-var-comment.yml +++ b/playbooks/templates/.github/workflows/ansible-managed-var-comment.yml @@ -2,6 +2,13 @@ name: Check for ansible_managed variable use in comments on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -13,11 +20,43 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: permissions: contents: read + pull-requests: read jobs: ansible_managed_var_comment: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_ansible-managed-var-comment]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-managed-var-comment')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-managed-var-comment')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_ansible-managed-var-comment') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest steps: - name: Update pip, git @@ -27,10 +66,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Install tox, tox-lsr run: | diff --git a/playbooks/templates/.github/workflows/ansible-plugin-scan.yml b/playbooks/templates/.github/workflows/ansible-plugin-scan.yml index 98bee13..7a83959 100644 --- a/playbooks/templates/.github/workflows/ansible-plugin-scan.yml +++ b/playbooks/templates/.github/workflows/ansible-plugin-scan.yml @@ -2,6 +2,13 @@ name: Ansible Plugin Scan on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -13,11 +20,43 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: permissions: contents: read + pull-requests: read jobs: ansible_plugin_scan: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_ansible-plugin-scan]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-plugin-scan')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-plugin-scan')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_ansible-plugin-scan') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest steps: - name: Update pip, git @@ -27,10 +66,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Install tox, tox-lsr run: | diff --git a/playbooks/templates/.github/workflows/ansible-test.yml b/playbooks/templates/.github/workflows/ansible-test.yml index 62b7ab4..765c381 100644 --- a/playbooks/templates/.github/workflows/ansible-test.yml +++ b/playbooks/templates/.github/workflows/ansible-test.yml @@ -2,6 +2,13 @@ name: Ansible Test on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -16,11 +23,43 @@ env: LSR_ROLE2COLL_NAME: {{ lsr_name }} permissions: contents: read + pull-requests: read jobs: ansible_test: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_ansible-test]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_ansible-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_ansible-test') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest strategy: fail-fast: false # get all results, not just the first failure @@ -41,10 +80,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Install tox, tox-lsr run: | diff --git a/playbooks/templates/.github/workflows/codeql.yml b/playbooks/templates/.github/workflows/codeql.yml index e55c928..aee5993 100644 --- a/playbooks/templates/.github/workflows/codeql.yml +++ b/playbooks/templates/.github/workflows/codeql.yml @@ -5,6 +5,13 @@ on: # yamllint disable-line rule:truthy branches: ["main"] pull_request: branches: ["main"] + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -12,14 +19,49 @@ on: # yamllint disable-line rule:truthy - checks_requested schedule: {{ github_actions.codeql.schedule | to_nice_yaml(indent=2) | indent(width=4, first=true) -}} +permissions: + contents: read + pull-requests: read jobs: analyze: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_codeql]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_codeql')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_codeql')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_codeql') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) name: Analyze runs-on: ubuntu-latest permissions: + pull-requests: read actions: read contents: read security-events: write @@ -33,10 +75,27 @@ jobs: set -euxo pipefail sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Initialize CodeQL uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4.37.9 diff --git a/playbooks/templates/.github/workflows/codespell.yml b/playbooks/templates/.github/workflows/codespell.yml index ea7235e..6fbdc6a 100644 --- a/playbooks/templates/.github/workflows/codespell.yml +++ b/playbooks/templates/.github/workflows/codespell.yml @@ -2,20 +2,77 @@ --- name: Codespell on: # yamllint disable-line rule:truthy - - pull_request + pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created permissions: contents: read + pull-requests: read jobs: codespell: if: | - !(github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_codespell]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_codespell')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_codespell')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_codespell') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) name: Check for spelling errors runs-on: ubuntu-latest steps: + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Codespell uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # v2.2 diff --git a/playbooks/templates/.github/workflows/markdownlint.yml b/playbooks/templates/.github/workflows/markdownlint.yml index 78cb3a7..09143fa 100644 --- a/playbooks/templates/.github/workflows/markdownlint.yml +++ b/playbooks/templates/.github/workflows/markdownlint.yml @@ -3,6 +3,13 @@ name: Markdown Lint on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -14,11 +21,43 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: permissions: contents: read + pull-requests: read jobs: markdownlint: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_markdownlint]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_markdownlint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_markdownlint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_markdownlint') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest steps: - name: Update pip, git @@ -27,10 +66,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Check out code uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} # CHANGELOG.md is generated automatically from PR titles and descriptions # It might have issues but they are not critical diff --git a/playbooks/templates/.github/workflows/pr-title-lint.yml b/playbooks/templates/.github/workflows/pr-title-lint.yml index ff58df1..07d545a 100644 --- a/playbooks/templates/.github/workflows/pr-title-lint.yml +++ b/playbooks/templates/.github/workflows/pr-title-lint.yml @@ -5,6 +5,7 @@ on: # yamllint disable-line rule:truthy types: - opened - synchronize + - labeled - reopened - edited merge_group: @@ -14,8 +15,37 @@ on: # yamllint disable-line rule:truthy - checks_requested permissions: contents: read + pull-requests: read jobs: commit-checks: + if: | + ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_pr-title-lint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && (github.event.action == 'synchronize' + || github.event.action == 'reopened' + || github.event.action == 'edited') + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_pr-title-lint')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_pr-title-lint') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest steps: - uses: {{ gha_checkout_action }} diff --git a/playbooks/templates/.github/workflows/python-unit-test.yml b/playbooks/templates/.github/workflows/python-unit-test.yml index 888bb69..2253c8c 100644 --- a/playbooks/templates/.github/workflows/python-unit-test.yml +++ b/playbooks/templates/.github/workflows/python-unit-test.yml @@ -3,6 +3,13 @@ name: Python Unit Tests on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -14,11 +21,43 @@ on: # yamllint disable-line rule:truthy workflow_dispatch: permissions: contents: read + pull-requests: read jobs: python: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_python-unit-test]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_python-unit-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_python-unit-test')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_python-unit-test') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) strategy: matrix: pyver_os: @@ -43,12 +82,25 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: checkout PR {%- endraw +%} uses: {{ gha_checkout_action }} with: persist-credentials: false {%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} - name: Set up Python 2.7 if: ${{ matrix.pyver_os.ver == '2.7' }} diff --git a/playbooks/templates/.github/workflows/qemu-kvm-integration-tests.yml b/playbooks/templates/.github/workflows/qemu-kvm-integration-tests.yml index 6e09fe3..1c61e47 100644 --- a/playbooks/templates/.github/workflows/qemu-kvm-integration-tests.yml +++ b/playbooks/templates/.github/workflows/qemu-kvm-integration-tests.yml @@ -2,6 +2,13 @@ name: Test on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -14,13 +21,45 @@ on: # yamllint disable-line rule:truthy permissions: contents: read + pull-requests: read # This is required for the ability to create/update the Pull request status statuses: write jobs: scenario: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_qemu-kvm-integration-tests]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_qemu-kvm-integration-tests')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_qemu-kvm-integration-tests')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_qemu-kvm-integration-tests') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest strategy: @@ -51,10 +90,27 @@ jobs: ANSIBLE_INJECT_FACT_VARS: "false" steps: + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Check if platform is supported id: check_platform diff --git a/playbooks/templates/.github/workflows/shellcheck.yml b/playbooks/templates/.github/workflows/shellcheck.yml index dba9db5..9a177d6 100644 --- a/playbooks/templates/.github/workflows/shellcheck.yml +++ b/playbooks/templates/.github/workflows/shellcheck.yml @@ -2,6 +2,13 @@ name: ShellCheck on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -16,11 +23,43 @@ env: SHELLCHECK_OPTS: -e SC1091 permissions: contents: read + pull-requests: read jobs: shellcheck: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_shellcheck]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_shellcheck')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_shellcheck')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_shellcheck') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest steps: - name: Update git @@ -29,10 +68,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout repo uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Run ShellCheck id: shellcheck_id diff --git a/playbooks/templates/.github/workflows/test_converting_readme.yml b/playbooks/templates/.github/workflows/test_converting_readme.yml index 64d5602..b94dab6 100644 --- a/playbooks/templates/.github/workflows/test_converting_readme.yml +++ b/playbooks/templates/.github/workflows/test_converting_readme.yml @@ -3,6 +3,13 @@ name: Test converting README.md to README.html on: # yamllint disable-line rule:truthy pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created merge_group: branches: - main @@ -13,13 +20,46 @@ on: # yamllint disable-line rule:truthy - main permissions: contents: read + pull-requests: read jobs: test_converting_readme: if: | - !((github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) || - (github.event_name == 'push' && contains(github.event.head_commit.message, '[citest_skip]'))) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_test_converting_readme]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_test_converting_readme')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_test_converting_readme')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_test_converting_readme') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest permissions: + pull-requests: read contents: write steps: - name: Update pip, git @@ -28,10 +68,27 @@ jobs: sudo apt update sudo apt install -y git + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Check out code uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Remove badges from README.md prior to converting to HTML run: sed -i '1,8 {/^\[\!.*actions\/workflows/d}' README.md diff --git a/playbooks/templates/.github/workflows/tft.yml b/playbooks/templates/.github/workflows/tft.yml index 907ce54..5554d15 100644 --- a/playbooks/templates/.github/workflows/tft.yml +++ b/playbooks/templates/.github/workflows/tft.yml @@ -1,11 +1,17 @@ --- name: Run integration tests in Testing Farm on: + pull_request: + types: + - opened + - synchronize + - labeled issue_comment: types: - created permissions: contents: read + pull-requests: read # This is required for the ability to create/update the Pull request status statuses: write jobs: @@ -13,17 +19,50 @@ jobs: name: Get info from role and PR to determine if and how to test # The concurrency key is used to prevent multiple workflows from running at the same time concurrency: - {%- raw %} +{%- raw %} # group name contains reponame-pr_num to allow simualteneous runs in different PRs - group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number }} + group: testing-farm-${{ github.event.repository.name }}-${{ github.event.issue.number || github.event.number }} cancel-in-progress: true # Let's schedule tests only on user request. NOT automatically. # Only repository owner or member can schedule tests if: | - github.event.issue.pull_request - && contains(github.event.comment.body, '[citest]') - && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) - || github.event.comment.user.login == 'systemroller') + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest]') + || contains(github.event.comment.body, '[citest_tft]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest') + || contains(github.event.pull_request.labels.*.name, 'citest_tft')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest') + || contains(github.event.pull_request.labels.*.name, 'citest_tft')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest' + || github.event.label.name == 'citest_tft') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) runs-on: ubuntu-latest outputs: supported_platforms: ${{ steps.supported_platforms.outputs.supported_platforms }} @@ -31,18 +70,16 @@ jobs: memory: ${{ steps.memory.outputs.memory }} steps: - name: Dump github context + if: env.SR_DEBUG == 'true' run: echo "$GITHUB_CONTEXT" shell: bash env: GITHUB_CONTEXT: ${{ toJson(github) }} + SR_DEBUG: 'false' # set to true to debug {%- endraw +%} - - name: Checkout repo - uses: {{ gha_checkout_action }} - with: - persist-credentials: false - - name: Get head sha of the PR + if: github.event_name == 'issue_comment' id: head_sha run: | head_sha=$(gh api "repos/$REPO/pulls/$PR_NO" --jq '.head.sha') @@ -50,7 +87,7 @@ jobs: env: {%- raw %} REPO: ${{ github.repository }} - PR_NO: ${{ github.event.issue.number }} + PR_NO: ${{ github.event.issue.number || github.event.number }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} {%- endraw +%} @@ -59,7 +96,7 @@ jobs: with: persist-credentials: false {%- raw %} - ref: ${{ steps.head_sha.outputs.head_sha }} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} {%- endraw +%} - name: Get memory @@ -126,7 +163,7 @@ jobs: ansible_version: "2.17" runs-on: ubuntu-latest env: - ARTIFACTS_DIR_NAME: "tf_${{ github.event.repository.name }}-${{ github.event.issue.number }}_\ + ARTIFACTS_DIR_NAME: "tf_${{ github.event.repository.name }}-${{ github.event.issue.number || github.event.number }}_\ ${{ matrix.platform }}-${{ matrix.ansible_version }}_\ ${{ needs.prepare_vars.outputs.datetime }}/artifacts" ARTIFACT_TARGET_DIR: /srv/pub/alt/${{ vars.SR_LSR_USER }}/logs @@ -135,7 +172,7 @@ jobs: id: set_vars run: | printf -v DATETIME '%(%Y%m%d-%H%M%S)T' -1 - ARTIFACTS_DIR_NAME="tf_${{ github.event.repository.name }}-${{ github.event.issue.number }}_\ + ARTIFACTS_DIR_NAME="tf_${{ github.event.repository.name }}-${{ github.event.issue.number || github.event.number }}_\ ${{ matrix.platform }}-${{ matrix.ansible_version }}_$DATETIME/artifacts" ARTIFACTS_TARGET_DIR=/srv/pub/alt/${{ vars.SR_LSR_USER }}/logs ARTIFACTS_DIR=$ARTIFACTS_TARGET_DIR/$ARTIFACTS_DIR_NAME @@ -175,7 +212,7 @@ jobs: variables: "SR_ANSIBLE_VER=${{ matrix.ansible_version }};\ SR_REPO_NAME=${{ github.event.repository.name }};\ SR_GITHUB_ORG=${{ github.repository_owner }};\ - SR_PR_NUM=${{ github.event.issue.number }};\ + SR_PR_NUM=${{ github.event.issue.number || github.event.number }};\ SR_ARTIFACTS_DIR=${{ steps.set_vars.outputs.ARTIFACTS_DIR }};\ SR_TEST_LOCAL_CHANGES=false;\ SR_LSR_USER=${{ vars.SR_LSR_USER }};\ diff --git a/playbooks/templates/.github/workflows/weekly_ci.yml b/playbooks/templates/.github/workflows/weekly_ci.yml index 9742439..b901945 100644 --- a/playbooks/templates/.github/workflows/weekly_ci.yml +++ b/playbooks/templates/.github/workflows/weekly_ci.yml @@ -12,7 +12,7 @@ env: This PR is for the purpose of triggering periodic CI testing. We don't currently have a way to trigger CI without a PR, so this PR serves that purpose. - COMMENT: "[citest]" + COMMENT: "[citest_tft]" permissions: contents: read jobs: diff --git a/playbooks/templates/.github/workflows/woke.yml b/playbooks/templates/.github/workflows/woke.yml index b170ced..435354e 100644 --- a/playbooks/templates/.github/workflows/woke.yml +++ b/playbooks/templates/.github/workflows/woke.yml @@ -2,20 +2,77 @@ # yamllint disable rule:line-length name: Woke on: # yamllint disable-line rule:truthy - - pull_request + pull_request: + types: + - opened + - synchronize + - labeled + issue_comment: + types: + - created permissions: contents: read + pull-requests: read jobs: woke: if: | - !(github.event_name == 'pull_request' && contains(github.event.pull_request.title, '[citest_skip]')) + ( + github.event_name == 'issue_comment' + && github.event.issue.pull_request + && (contains(github.event.comment.body, '[citest_all]') + || contains(github.event.comment.body, '[citest_woke]')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.comment.author_association) + || github.event.comment.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'opened' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_woke')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.pull_request.user.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'synchronize' + && (contains(github.event.pull_request.labels.*.name, 'citest_all') + || contains(github.event.pull_request.labels.*.name, 'citest_woke')) + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) || ( + github.event_name == 'pull_request' + && github.event.action == 'labeled' + && (github.event.label.name == 'citest_all' + || github.event.label.name == 'citest_woke') + && (contains(fromJson('["OWNER", "MEMBER", "COLLABORATOR"]'), + github.event.pull_request.author_association) + || github.event.sender.login == 'systemroller') + ) name: Detect non-inclusive language runs-on: ubuntu-latest steps: + - name: Get PR head SHA + if: github.event_name == 'issue_comment' + id: head_sha + env: +{%- raw %} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.issue.number }} +{%- endraw +%} + run: | + set -euxo pipefail + head_sha=$(gh api "repos/$REPO/pulls/$PR_NUMBER" --jq '.head.sha') + echo "head_sha=$head_sha" >> "$GITHUB_OUTPUT" + - name: Checkout uses: {{ gha_checkout_action }} with: persist-credentials: false +{%- raw %} + ref: ${{ steps.head_sha.outputs.head_sha || github.sha }} +{%- endraw +%} - name: Run lsr-woke-action # Originally, uses: get-woke/woke-action@v0 diff --git a/playbooks/update_files.yml b/playbooks/update_files.yml index 1787d3e..e7abe70 100644 --- a/playbooks/update_files.yml +++ b/playbooks/update_files.yml @@ -146,15 +146,6 @@ when: item | length > 0 changed_when: false - - name: Process files to be added or updated - copy: - src: "{{ item }}" - dest: "{{ git_dir }}/{{ item }}" - mode: preserve - loop: "{{ present_files + __present_python_files + - __present_shellcheck_files }}" - changed_when: false - - name: Process files to be removed shell: chdir: "{{ git_dir }}" @@ -168,6 +159,15 @@ changed_when: false loop: "{{ __all_absent }}" + - name: Process files to be added or updated + copy: + src: "{{ item }}" + dest: "{{ git_dir }}/{{ item }}" + mode: preserve + loop: "{{ present_files + __present_python_files + + __present_shellcheck_files }}" + changed_when: false + # NOTE: Some of the templates are github action definitions # which use ${{ var }} - you may have to put {%- raw %} # {%- endraw +%} blocks around them. @@ -186,6 +186,43 @@ ([__role_template_dir] | product(__role_present_templates)) }}" changed_when: false + - name: Ensure citest labels exist + shell: + chdir: "{{ git_dir }}" + cmd: | + set -euo pipefail + repo="{{ github_org }}/{{ inventory_hostname }}" + labels=(citest citest_all) + shopt -s nullglob + for wf in .github/workflows/*.yml; do + base=$(basename "$wf") + case "$base" in + build_docs.yml|changelog_to_tag.yml|tft_citest_bad.yml|weekly_ci.yml) + continue + ;; + esac + labels+=("citest_${base%.yml}") + done + existing=$(gh label list --repo "$repo" --limit 1000 --json name --jq '.[].name') + added=0 + for label in "${labels[@]}"; do + if printf '%s\n' "$existing" | grep -Fxq "$label"; then + continue + fi + echo "Creating label $label on $repo" + added=1 + if [ {{ lsr_dry_run | d('true') }} = false ]; then + gh label create "$label" --repo "$repo" \ + --color 0E8A16 \ + --description "Trigger CI tests ($label)" + fi + done + if [ "$added" -eq 1 ]; then + echo CHANGED + fi + register: __citest_labels + changed_when: "'CHANGED' in __citest_labels.stdout" + - name: Find workflows to create badges for find: paths: "{{ git_dir }}/.github/workflows"