Skip to content

[main] Merge upstream prometheus/main to d5cc5e2738e2 #3122

[main] Merge upstream prometheus/main to d5cc5e2738e2

[main] Merge upstream prometheus/main to d5cc5e2738e2 #3122

Workflow file for this run

name: ci
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
strategy:
matrix:
include:
- buildtags: slicelabels # there's no such tag when this is being written, but it makes the CI job name more obvious.
testargs: -race
- buildtags: stringlabels
testargs: -race
- buildtags: dedupelabels
# Run dedupelabels without race detection, as it causes CI runners to OOM.
fail-fast: false
name: test (${{ matrix.buildtags }})
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/[email protected]
with:
go-version: '~1.24.0'
cache: false # We do this ourselves below to avoid conflicts between the different jobs.
- name: Get Go paths
id: gopaths
run: |
echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ${{ steps.gopaths.outputs.GOMODCACHE }}
# Use the same dependencies cache for all instances of this 'test' job, given each will use the same dependencies.
# We don't share this cache with the 'fuzz' job below because it only uses (and therefore downloads) a subset of dependencies.
key: ci-test-dependencies-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Cache build cache
uses: actions/[email protected]
with:
path: ${{ steps.gopaths.outputs.GOCACHE }}
# Use a unique build cache for each instance of this 'test' job, given each will be built with different build tags.
key: ci-test-build-cache-${{ runner.os }}-${{ matrix.buildtags }}-${{ hashFiles('**/go.sum') }}
- name: Run Tests
run: go test -tags=${{ matrix.buildtags }} ${{ matrix.testargs }} -timeout=20m ./...
fuzz:
strategy:
matrix:
include:
- package: ./model/labels
fuzz: FuzzFastRegexMatcher_WithStaticallyDefinedRegularExpressions
- package: ./model/labels
fuzz: FuzzFastRegexMatcher_WithFuzzyRegularExpressions
runs-on: ubuntu-24.04
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/[email protected]
with:
go-version: '~1.24.0'
cache: false # We do this ourselves below to avoid conflicts between the different jobs.
- name: Get Go paths
id: gopaths
run: |
echo "GOMODCACHE=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
echo "GOCACHE=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ${{ steps.gopaths.outputs.GOMODCACHE }}
# Use the same dependencies cache for all instances of this 'fuzz' job, given each will use the same dependencies.
key: ci-fuzz-dependencies-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Cache build cache
uses: actions/[email protected]
with:
path: ${{ steps.gopaths.outputs.GOCACHE }}
# Use the same build cache for each instance of this 'fuzz' job, given each will build the same package (model/labels) with the same build tags.
key: ci-fuzz-build-cache-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Set -fuzztime=10m for 'main' branch
if: github.ref == 'refs/heads/main'
run: echo "fuzztime=10m" >> $GITHUB_ENV
- name: Set -fuzztime=1m for non-'main' branches
if: github.ref != 'refs/heads/main'
run: echo "fuzztime=1m" >> $GITHUB_ENV
- name: Fuzz
run: go test -run=NOTHING -fuzz=${{ matrix.fuzz }} -fuzztime=$fuzztime ${{ matrix.package }}
notify-failure:
runs-on: ubuntu-latest
needs: test
if: ${{ failure() && needs.test.result == 'failure' }}
permissions:
contents: read
id-token: write
steps:
- name: Check if upstream merge PR failed
id: check-failure
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
# Check if this is an upstream merge branch
if [[ "$BRANCH_NAME" == bot/main/merge-upstream-* ]]; then
echo "should_notify=true" >> $GITHUB_OUTPUT
echo "This is an upstream merge branch and test failed"
fi
- name: Get PR URL if exists
id: get-pr-url
if: steps.check-failure.outputs.should_notify == 'true'
env:
EVENT_NAME: ${{ github.event_name }}
PR_HTML_URL: ${{ github.event.pull_request.html_url }}
PR_NUMBER: ${{ github.event.pull_request.number }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Try to get PR URL for this branch
if [ "$EVENT_NAME" = "pull_request" ]; then
echo "pr_url=$PR_HTML_URL" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
else
# For push events, try to find the PR
PR_INFO=$(gh pr list --head "$BRANCH_NAME" --json number,url --limit 1)
if [ "$PR_INFO" != "[]" ]; then
PR_URL=$(echo "$PR_INFO" | jq -r '.[0].url')
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.[0].number')
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
fi
fi
- name: Send Slack notification for test failure
if: steps.check-failure.outputs.should_notify == 'true'
env:
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
RUN_ID: ${{ github.run_id }}
PR_URL: ${{ steps.get-pr-url.outputs.pr_url }}
PR_NUMBER: ${{ steps.get-pr-url.outputs.pr_number }}
uses: grafana/shared-workflows/actions/send-slack-message@7b628e7352c2dea057c565cc4fcd5564d5f396c0 #v1.0.0
with:
channel-id: C04AF91LPFX #mimir-ci-notifications
payload: |
{
"text": ":warning: *Test failed for upstream merge PR*\n\n`test (stringlabels)` failed for upstream merge PR: <${{ env.PR_URL || format('{0}/{1}/tree/{2}', env.SERVER_URL, env.REPOSITORY, env.BRANCH_NAME) }}|${{ env.PR_NUMBER && format('PR #{0}', env.PR_NUMBER) || format('Branch {0}', env.BRANCH_NAME) }}>\n\nWorkflow run: <${{ env.SERVER_URL }}/${{ env.REPOSITORY }}/actions/runs/${{ env.RUN_ID }}|View failure details>"
}