mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-02 13:39:49 +00:00
This PR introduces a new `ActionRunAttempt` model and makes Actions
execution attempt-scoped.
**Main Changes**
- Each workflow run trigger generates a new `ActionRunAttempt`. The
triggered jobs are then associated with this new `ActionRunAttempt`
record.
- Each rerun now creates:
- a new `ActionRunAttempt` record for the workflow run
- a full new set of `ActionRunJob` records for the new
`ActionRunAttempt`
- For jobs that need to be rerun, the new job records are created as
runnable jobs in the new attempt.
- For jobs that do not need to be rerun, new job records are still
created in the new attempt, but they reuse the result of the previous
attempt instead of executing again.
- Introduce `rerunPlan` to manage each rerun and refactored rerun flow
into a two-phase plan-based model:
- `buildRerunPlan`
- `execRerunPlan`
- `RerunFailedWorkflowRun` and `RerunFailed` no longer directly derives
all jobs that need to be rerun; this step is now handled by
`buildRerunPlan`.
- Converted artifacts from run-scoped to attempt-scoped:
- uploads are now associated with `RunAttemptID`
- listing, download, and deletion resolve against the current attempt
- Added attempt-aware web Actions views:
- the default run page shows the latest attempt
(`/actions/runs/{run_id}`)
- previous attempt pages show jobs and artifacts for that attempt
(`/actions/runs/{run_id}/attempts/{attempt_num}`)
- New APIs:
- `/repos/{owner}/{repo}/actions/runs/{run}/attempts/{attempt}`
- `/repos/{owner}/{repo}/actions/runs/{run}/attempts/{attempt}/jobs`
- New configuration `MAX_RERUN_ATTEMPTS`
- https://gitea.com/gitea/docs/pulls/383
**Compatibility**
- Existing legacy runs use `LatestAttemptID = 0` and legacy jobs use
`RunAttemptID = 0`. Therefore, these fields can be used to identify
legacy runs and jobs and provide backward compatibility.
- If a legacy run is rerun, an `ActionRunAttempt` with `attempt=1` will
be created to represent the original execution. Then a new
`ActionRunAttempt` with `attempt=2` will be created for the real rerun.
- Existing artifact records are not backfilled; legacy artifacts
continue to use `RunAttemptID = 0`.
**Improvements**
- It is now easier to inspect and download logs from previous attempts.
-
[`run_attempt`](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#github-context)
semantics are now aligned with GitHub.
- > A unique number for each attempt of a particular workflow run in a
repository. This number begins at 1 for the workflow run's first
attempt, and increments with each re-run.
- Rerun behavior is now clearer and more explicit.
- Instead of mutating the status of previous jobs in place, each rerun
creates a new attempt with a full new set of job records.
- Artifacts produced by different reruns can now be listed separately.
Signed-off-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Giteabot <teabot@gitea.io>
179 lines
6.0 KiB
TypeScript
179 lines
6.0 KiB
TypeScript
import './relative-time.ts';
|
|
|
|
function createRelativeTime(datetime: string, attrs: Record<string, string> = {}): HTMLElement {
|
|
const el = document.createElement('relative-time');
|
|
el.setAttribute('lang', 'en');
|
|
el.setAttribute('datetime', datetime);
|
|
for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
|
|
return el;
|
|
}
|
|
|
|
function getText(el: HTMLElement): string {
|
|
return el.shadowRoot!.textContent ?? '';
|
|
}
|
|
|
|
test('renders "now" for current time', async () => {
|
|
const el = createRelativeTime(new Date().toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('now');
|
|
});
|
|
|
|
test('renders minutes ago', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 3 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('3 minutes ago');
|
|
});
|
|
|
|
test('renders hours ago', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 3 * 60 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('3 hours ago');
|
|
});
|
|
|
|
test('renders yesterday', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('yesterday');
|
|
});
|
|
|
|
test('renders days ago', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('3 days ago');
|
|
});
|
|
|
|
test('renders future time', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() + 3 * 24 * 60 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('in 3 days');
|
|
});
|
|
|
|
test('switches to datetime format after default threshold', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 32 * 24 * 60 * 60 * 1000).toISOString(), {lang: 'en-US'});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toMatch(/on [A-Z][a-z]{2} \d{1,2}/);
|
|
});
|
|
|
|
test('accepts unix seconds as integer string', async () => {
|
|
const el = createRelativeTime(String(Math.floor(Date.now() / 1000) - 3 * 60));
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('3 minutes ago');
|
|
});
|
|
|
|
test('ignores fractional unix seconds', async () => {
|
|
const el = createRelativeTime('1700000000.5');
|
|
el.shadowRoot!.textContent = 'fallback';
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('fallback');
|
|
});
|
|
|
|
test('ignores negative unix seconds', async () => {
|
|
const el = createRelativeTime('-86400');
|
|
el.shadowRoot!.textContent = 'fallback';
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('fallback');
|
|
});
|
|
|
|
test('ignores invalid datetime', async () => {
|
|
const el = createRelativeTime('bogus');
|
|
el.shadowRoot!.textContent = 'fallback';
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('fallback');
|
|
});
|
|
|
|
test('ignores partial numeric datetime', async () => {
|
|
const el = createRelativeTime('123abc');
|
|
el.shadowRoot!.textContent = 'fallback';
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('fallback');
|
|
});
|
|
|
|
test('handles empty datetime', async () => {
|
|
const el = createRelativeTime('');
|
|
el.shadowRoot!.textContent = 'fallback';
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('fallback');
|
|
});
|
|
|
|
test('tense=past shows relative time beyond threshold', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 60 * 24 * 60 * 60 * 1000).toISOString(), {tense: 'past'});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toMatch(/months? ago/);
|
|
});
|
|
|
|
test('tense=past clamps future to now', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() + 3000).toISOString(), {tense: 'past'});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('now');
|
|
});
|
|
|
|
test('format=duration renders duration', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 3 * 60 * 60 * 1000).toISOString(), {format: 'duration'});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toMatch(/hours?/);
|
|
});
|
|
|
|
test('format=datetime renders formatted date', async () => {
|
|
const el = createRelativeTime(new Date().toISOString(), {format: 'datetime', lang: 'en-US'});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toMatch(/[A-Z][a-z]{2}, [A-Z][a-z]{2} \d{1,2}/);
|
|
});
|
|
|
|
test('sets data-tooltip-content', async () => {
|
|
const el = createRelativeTime(new Date().toISOString());
|
|
await Promise.resolve();
|
|
expect(el.getAttribute('data-tooltip-content')).toBeTruthy();
|
|
expect(el.getAttribute('aria-label')).toBe(el.getAttribute('data-tooltip-content'));
|
|
});
|
|
|
|
test('respects lang from parent element', async () => {
|
|
const container = document.createElement('span');
|
|
container.setAttribute('lang', 'de');
|
|
const el = document.createElement('relative-time');
|
|
el.setAttribute('datetime', new Date(Date.now() - 3 * 24 * 60 * 60 * 1000).toISOString());
|
|
container.append(el);
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('vor 3 Tagen');
|
|
});
|
|
|
|
test('falls back when navigator.language is invalid', async () => {
|
|
vi.spyOn(navigator, 'language', 'get').mockReturnValue('undefined');
|
|
try {
|
|
const el = document.createElement('relative-time');
|
|
el.setAttribute('datetime', new Date(Date.now() - 3 * 60 * 1000).toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('3 minutes ago');
|
|
} finally {
|
|
vi.restoreAllMocks();
|
|
}
|
|
});
|
|
|
|
test('switches to datetime with P1D threshold', async () => {
|
|
const el = createRelativeTime(new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString(), {
|
|
lang: 'en-US',
|
|
threshold: 'P1D',
|
|
});
|
|
await Promise.resolve();
|
|
expect(getText(el)).toMatch(/on [A-Z][a-z]{2} \d{1,2}/);
|
|
});
|
|
|
|
test('batches multiple attribute changes into single update', async () => {
|
|
const el = document.createElement('relative-time');
|
|
el.setAttribute('lang', 'en');
|
|
el.setAttribute('datetime', new Date().toISOString());
|
|
await Promise.resolve();
|
|
expect(getText(el)).toBe('now');
|
|
|
|
let updateCount = 0;
|
|
const origUpdate = (el as any).update;
|
|
(el as any).update = function () {
|
|
updateCount++;
|
|
return origUpdate.call(this);
|
|
};
|
|
el.setAttribute('second', '2-digit');
|
|
el.setAttribute('hour', '2-digit');
|
|
el.setAttribute('minute', '2-digit');
|
|
await Promise.resolve();
|
|
expect(updateCount).toBe(1);
|
|
});
|