mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-06-22 01:34:25 +02:00
Compare commits
3 Commits
7b5ebe9618
...
0e0c54b272
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e0c54b272 | ||
|
|
d6fbe75721 | ||
|
|
b30204aa94 |
27
.gitea/workflows/pull-pr-title.yml
Normal file
27
.gitea/workflows/pull-pr-title.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
name: pr-title
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- edited
|
||||||
|
- reopened
|
||||||
|
- synchronize
|
||||||
|
- ready_for_review
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint-pr-title:
|
||||||
|
if: github.event.pull_request.draft == false
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 5
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
- run: make lint-pr-title
|
||||||
|
env:
|
||||||
|
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
/gitea-runner
|
/gitea-runner
|
||||||
.env
|
.env
|
||||||
|
!/act/runner/testdata/secrets/.env
|
||||||
.runner
|
.runner
|
||||||
coverage.txt
|
coverage.txt
|
||||||
/config.yaml
|
/config.yaml
|
||||||
@@ -10,4 +11,4 @@ coverage.txt
|
|||||||
.vscode
|
.vscode
|
||||||
__debug_bin
|
__debug_bin
|
||||||
# gorelease binary folder
|
# gorelease binary folder
|
||||||
dist
|
/dist
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -118,6 +118,10 @@ lint-go: ## lint go files
|
|||||||
lint-go-fix: ## lint go files and fix issues
|
lint-go-fix: ## lint go files and fix issues
|
||||||
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
|
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
|
||||||
|
|
||||||
|
.PHONY: lint-pr-title
|
||||||
|
lint-pr-title: ## lint PR title against Conventional Commits (set PR_TITLE=...)
|
||||||
|
@node ./tools/lint-pr-title.ts
|
||||||
|
|
||||||
.PHONY: security-check
|
.PHONY: security-check
|
||||||
security-check: deps-tools
|
security-check: deps-tools
|
||||||
GOEXPERIMENT= $(GO) run $(GOVULNCHECK_PACKAGE) -show color ./... || true
|
GOEXPERIMENT= $(GO) run $(GOVULNCHECK_PACKAGE) -show color ./... || true
|
||||||
|
|||||||
@@ -601,10 +601,34 @@ func (rc *RunContext) interpolateOutputs() common.Executor {
|
|||||||
|
|
||||||
func (rc *RunContext) startContainer() common.Executor {
|
func (rc *RunContext) startContainer() common.Executor {
|
||||||
return func(ctx context.Context) error {
|
return func(ctx context.Context) error {
|
||||||
|
var err error
|
||||||
if rc.IsHostEnv(ctx) {
|
if rc.IsHostEnv(ctx) {
|
||||||
return rc.startHostEnvironment()(ctx)
|
err = rc.startHostEnvironment()(ctx)
|
||||||
|
} else {
|
||||||
|
err = rc.startJobContainer()(ctx)
|
||||||
}
|
}
|
||||||
return rc.startJobContainer()(ctx)
|
if err != nil {
|
||||||
|
// The job executor's teardown only runs after a successful start, so a failed
|
||||||
|
// start would otherwise leak the per-job network and container.
|
||||||
|
rc.cleanupFailedStart(ctx)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) cleanupFailedStart(ctx context.Context) {
|
||||||
|
if rc.cleanUpJobContainer == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cleanCtx := ctx
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
// the start likely failed because ctx was cancelled, detach so teardown still runs
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
cleanCtx, cancel = context.WithTimeout(common.WithLogger(context.Background(), common.Logger(ctx)), time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
}
|
||||||
|
if err := rc.cleanUpJobContainer(cleanCtx); err != nil {
|
||||||
|
common.Logger(ctx).Errorf("Error while cleaning up after failed container start for job %s: %v", rc.JobName, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
assert "github.com/stretchr/testify/assert"
|
assert "github.com/stretchr/testify/assert"
|
||||||
|
require "github.com/stretchr/testify/require"
|
||||||
yaml "go.yaml.in/yaml/v4"
|
yaml "go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -659,3 +660,53 @@ func TestPrintStartJobContainerGroupGolden(t *testing.T) {
|
|||||||
}, "\n")
|
}, "\n")
|
||||||
assert.Equal(t, want, buf.String())
|
assert.Equal(t, want, buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunContext_cleanupFailedStart(t *testing.T) {
|
||||||
|
type ctxKey string
|
||||||
|
const sentinel = ctxKey("sentinel")
|
||||||
|
|
||||||
|
// the fresh context is cancelled via defer on return, so capture state inside the stub
|
||||||
|
type capture struct {
|
||||||
|
calls int
|
||||||
|
err error
|
||||||
|
sentinel any
|
||||||
|
}
|
||||||
|
newRC := func(c *capture) *RunContext {
|
||||||
|
return &RunContext{
|
||||||
|
JobName: "job",
|
||||||
|
cleanUpJobContainer: func(ctx context.Context) error {
|
||||||
|
c.calls++
|
||||||
|
c.err = ctx.Err()
|
||||||
|
c.sentinel = ctx.Value(sentinel)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("runs teardown on the live context", func(t *testing.T) {
|
||||||
|
var c capture
|
||||||
|
ctx := context.WithValue(context.Background(), sentinel, "v")
|
||||||
|
|
||||||
|
newRC(&c).cleanupFailedStart(ctx)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, c.calls)
|
||||||
|
require.NoError(t, c.err)
|
||||||
|
assert.Equal(t, "v", c.sentinel)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("falls back to a fresh context when the input is done", func(t *testing.T) {
|
||||||
|
var c capture
|
||||||
|
ctx, cancel := context.WithCancel(context.WithValue(context.Background(), sentinel, "v"))
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
newRC(&c).cleanupFailedStart(ctx)
|
||||||
|
|
||||||
|
assert.Equal(t, 1, c.calls)
|
||||||
|
require.NoError(t, c.err)
|
||||||
|
assert.Nil(t, c.sentinel)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("no-op when there is nothing to clean up", func(t *testing.T) {
|
||||||
|
assert.NotPanics(t, func() { (&RunContext{}).cleanupFailedStart(context.Background()) })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/common"
|
"gitea.com/gitea/runner/act/common"
|
||||||
"gitea.com/gitea/runner/act/model"
|
"gitea.com/gitea/runner/act/model"
|
||||||
@@ -192,6 +193,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config
|
|||||||
Inputs: cfg.Inputs,
|
Inputs: cfg.Inputs,
|
||||||
GitHubInstance: "github.com",
|
GitHubInstance: "github.com",
|
||||||
ContainerArchitecture: cfg.ContainerArchitecture,
|
ContainerArchitecture: cfg.ContainerArchitecture,
|
||||||
|
ContainerMaxLifetime: time.Hour,
|
||||||
Matrix: cfg.Matrix,
|
Matrix: cfg.Matrix,
|
||||||
ActionCache: cfg.ActionCache,
|
ActionCache: cfg.ActionCache,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ outputs:
|
|||||||
description: 'The time we greeted you'
|
description: 'The time we greeted you'
|
||||||
runs:
|
runs:
|
||||||
using: 'node24'
|
using: 'node24'
|
||||||
main: 'dist/index.js'
|
main: 'index.js'
|
||||||
|
|||||||
21
act/runner/testdata/actions/node24/index.js
vendored
21
act/runner/testdata/actions/node24/index.js
vendored
@@ -1,11 +1,14 @@
|
|||||||
import {getInput, setOutput, setFailed} from '@actions/core';
|
import {appendFileSync, readFileSync} from 'node:fs';
|
||||||
import {context} from '@actions/github';
|
|
||||||
|
|
||||||
try {
|
const nameToGreet = process.env['INPUT_WHO-TO-GREET'] || 'World';
|
||||||
const nameToGreet = getInput('who-to-greet');
|
console.log(`Hello ${nameToGreet}!`);
|
||||||
console.log(`Hello ${nameToGreet}!`);
|
|
||||||
setOutput('time', (new Date()).toTimeString());
|
if (process.env.GITHUB_OUTPUT) {
|
||||||
console.log(`The event payload: ${JSON.stringify(context.payload, undefined, 2)}`);
|
appendFileSync(process.env.GITHUB_OUTPUT, `time=${new Date().toTimeString()}\n`);
|
||||||
} catch (error) {
|
|
||||||
setFailed(error.message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let payload = {};
|
||||||
|
if (process.env.GITHUB_EVENT_PATH) {
|
||||||
|
payload = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));
|
||||||
|
}
|
||||||
|
console.log(`The event payload: ${JSON.stringify(payload, undefined, 2)}`);
|
||||||
|
|||||||
20
act/runner/testdata/actions/node24/package.json
vendored
20
act/runner/testdata/actions/node24/package.json
vendored
@@ -1,21 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "node24",
|
"name": "node24",
|
||||||
"version": "1.0.0",
|
"private": true,
|
||||||
"description": "",
|
"type": "module"
|
||||||
"main": "index.js",
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"build": "ncc build index.js"
|
|
||||||
},
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"@actions/core": "^3.0.1",
|
|
||||||
"@actions/github": "^9.1.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vercel/ncc": "^0.38.4"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=24"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
act/runner/testdata/secrets/.env
vendored
Normal file
2
act/runner/testdata/secrets/.env
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
HELLO=WORLD
|
||||||
|
MULTILINE_ENV="foo\nbar\nbaz"
|
||||||
19
tools/lint-pr-title.ts
Normal file
19
tools/lint-pr-title.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import {env, exit} from 'node:process';
|
||||||
|
|
||||||
|
const allowedTypes = 'build, chore, ci, docs, enhance, feat, fix, perf, refactor, revert, style, test';
|
||||||
|
const title = env.PR_TITLE;
|
||||||
|
|
||||||
|
if (!title) {
|
||||||
|
console.error('Missing PR_TITLE');
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const validTitlePattern = new RegExp(`^(${allowedTypes.replaceAll(', ', '|')})(\\([\\w.-]+\\))?(!)?: .+$`);
|
||||||
|
|
||||||
|
if (!validTitlePattern.test(title)) {
|
||||||
|
console.error(`Invalid PR title: ${title}`);
|
||||||
|
console.error('Expected format: type(scope): subject');
|
||||||
|
console.error(`Allowed types: ${allowedTypes}`);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user