mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-09 17:37:20 -06:00
Runs triggered by `workflow_dispatch` never created a commit status, so the commit showed no sign that a workflow ran on it. - Post the status on the run's commit, e.g. `ci / e2e (workflow_dispatch)`. `schedule` runs stay unchanged. - These statuses don't count for pull requests. They don't show in a PR's checks and can't satisfy or fail its required checks, even through broad globs like `ci / e2e*`. Closes https://github.com/go-gitea/gitea/issues/39639 --------- Co-authored-by: silverwind <me@silverwind.io>
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
|
|
actions_module "gitea.dev/modules/actions"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDeriveScopedStatusContexts(t *testing.T) {
|
|
t.Run("jobs x events; job name is its unescaped name: or its id", func(t *testing.T) {
|
|
content := []byte(`name: CI
|
|
on: [push, pull_request]
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- run: echo
|
|
build:
|
|
name: Build It
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- run: echo
|
|
test:
|
|
name: "${{ matrix.os }} ${{ '${{' }}"
|
|
strategy:
|
|
matrix:
|
|
os: [linux]
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- run: echo
|
|
`)
|
|
events, err := actions_module.GetEventsFromContent(content)
|
|
require.NoError(t, err)
|
|
got := deriveScopedStatusContexts("org/src", "CI", content, events)
|
|
assert.ElementsMatch(t, []string{
|
|
"org/src: CI / lint (push)",
|
|
"org/src: CI / lint (pull_request)",
|
|
"org/src: CI / Build It (push)",
|
|
"org/src: CI / Build It (pull_request)",
|
|
"org/src: CI / linux ${{ (push)",
|
|
"org/src: CI / linux ${{ (pull_request)",
|
|
}, got)
|
|
})
|
|
|
|
t.Run("only pull request check events; workflow_dispatch/schedule/workflow_call skipped", func(t *testing.T) {
|
|
content := []byte(`name: CI
|
|
on:
|
|
push:
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
schedule:
|
|
- cron: "0 0 * * *"
|
|
jobs:
|
|
j:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- run: echo
|
|
`)
|
|
events, err := actions_module.GetEventsFromContent(content)
|
|
require.NoError(t, err)
|
|
got := deriveScopedStatusContexts("org/src", "CI", content, events)
|
|
assert.Equal(t, []string{"org/src: CI / j (push)"}, got)
|
|
})
|
|
}
|