CI: Avoid running on 'push' in mirrors / forks (#110063)

* CI: Avoid running on 'push' in mirrors / forks

* use single quotes
This commit is contained in:
Kevin Minehart 2025-08-22 18:35:52 -05:00 committed by GitHub
parent d51e6a16bc
commit 488caa12ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 23 additions and 6 deletions

View File

@ -14,6 +14,8 @@ permissions:
jobs: jobs:
detect-changes: detect-changes:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
name: Detect whether code changed name: Detect whether code changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:

View File

@ -12,4 +12,6 @@ on:
jobs: jobs:
verify-i18n: verify-i18n:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
uses: grafana/grafana-github-actions/.github/workflows/verify-i18n.yml@main uses: grafana/grafana-github-actions/.github/workflows/verify-i18n.yml@main

View File

@ -20,6 +20,8 @@ permissions: {}
jobs: jobs:
docs: docs:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
name: Build & Verify Docs name: Build & Verify Docs
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -10,6 +10,8 @@ permissions: {}
jobs: jobs:
detect-changes: detect-changes:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
name: Detect whether code changed name: Detect whether code changed
runs-on: ubuntu-x64-small runs-on: ubuntu-x64-small
permissions: permissions:
@ -166,4 +168,4 @@ jobs:
with: with:
needs: ${{ toJson(needs) }} needs: ${{ toJson(needs) }}
failure-message: "One or more unit test jobs have failed" failure-message: "One or more unit test jobs have failed"
success-message: "All unit tests completed successfully" success-message: "All unit tests completed successfully"

View File

@ -12,6 +12,8 @@ permissions: {}
jobs: jobs:
reject-gh-secrets: reject-gh-secrets:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: read
@ -28,4 +30,4 @@ jobs:
echo "Found secrets access in the codebase. Please remove it in favour of Vault secrets." echo "Found secrets access in the codebase. Please remove it in favour of Vault secrets."
echo "If you are sure this is correct, add '# nolint:reject-gh-secrets' to the end of the line. Be VERY careful with this." echo "If you are sure this is correct, add '# nolint:reject-gh-secrets' to the end of the line. Be VERY careful with this."
exit 1 exit 1
fi fi

View File

@ -49,7 +49,7 @@ jobs:
setup: setup:
name: setup name: setup
runs-on: github-hosted-ubuntu-x64-small runs-on: github-hosted-ubuntu-x64-small
if: github.repository == 'grafana/grafana' if: (github.repository == 'grafana/grafana') || (github.repository == 'grafana/grafana-security-mirror' && contains(github.ref_name, '+security'))
outputs: outputs:
version: ${{ steps.output.outputs.version }} version: ${{ steps.output.outputs.version }}
grafana-commit: ${{ steps.output.outputs.grafana_commit }} grafana-commit: ${{ steps.output.outputs.grafana_commit }}
@ -104,10 +104,11 @@ jobs:
BUCKET: grafana-prerelease BUCKET: grafana-prerelease
GRAFANA_COMMIT: ${{ needs.setup.outputs.grafana-commit }} GRAFANA_COMMIT: ${{ needs.setup.outputs.grafana-commit }}
SOURCE_EVENT: ${{ inputs.source-event || github.event_name }} SOURCE_EVENT: ${{ inputs.source-event || github.event_name }}
REPO: ${{ github.repository }}
with: with:
github-token: ${{ steps.generate_token.outputs.token }} github-token: ${{ steps.generate_token.outputs.token }}
script: | script: |
const {REF, VERSION, BUILD_ID, BUCKET, GRAFANA_COMMIT, SOURCE_EVENT} = process.env; const {REF, VERSION, BUILD_ID, BUCKET, GRAFANA_COMMIT, SOURCE_EVENT, REPO} = process.env;
await github.rest.actions.createWorkflowDispatch({ await github.rest.actions.createWorkflowDispatch({
owner: 'grafana', owner: 'grafana',
@ -120,6 +121,7 @@ jobs:
"bucket": BUCKET, "bucket": BUCKET,
"grafana-commit": GRAFANA_COMMIT, "grafana-commit": GRAFANA_COMMIT,
"source-event": SOURCE_EVENT, "source-event": SOURCE_EVENT,
"upstream": REPO,
} }
}) })

View File

@ -15,6 +15,8 @@ permissions: {}
jobs: jobs:
shellcheck: shellcheck:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
name: Shellcheck scripts name: Shellcheck scripts
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:

View File

@ -15,6 +15,8 @@ concurrency:
jobs: jobs:
detect-changes: detect-changes:
# Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' || (github.event_name == 'push' && github.repository == 'grafana/grafana'))
name: Detect whether code changed name: Detect whether code changed
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:

View File

@ -22,7 +22,8 @@ env:
jobs: jobs:
trigger-search-e2e: trigger-search-e2e:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.event.pull_request.draft == false # Run on `grafana/grafana` main branch, or on pull requests to prevent double-running on mirrors
if: (github.event_name == 'pull_request' && github.event.pull_request.draft == false) || (github.event_name == 'push' && github.repository == 'grafana/grafana')
steps: steps:
- name: Trigger Dashboard Search E2E - name: Trigger Dashboard Search E2E
run: echo "Triggered Dashboard Search e2e..." run: echo "Triggered Dashboard Search e2e..."