Skip to content

Commit

Permalink
bt forgejo_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
RagnarGrootKoerkamp committed Nov 10, 2024
1 parent cebb331 commit f8ff15c
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bin/skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,37 @@ def problem_source_dir(problem):
problem = problem_obj.name
print('\n')
print(substitute(problem_yml, locals()), end='')


def create_forgejo_actions(contest, problems):
if Path('.git').is_dir():
contest_path = Path('.')
forgejo = Path('.forgejo')
elif Path('../.git').is_dir():
contest_path = Path(contest)
forgejo = Path('../.forgejo')
else:
fatal('.git and ../.git not found after changing to contest directory.')

# Copy the 'setup' action:
setup_action_source = config.tools_root / 'skel/forgejo_actions/setup.yaml'
setup_action_target = forgejo / Path('actions/setup/action.yml')
setup_action_target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(setup_action_source, setup_action_target)

# Copy the contest-level workflow.
contest_workflow_source = (config.tools_root / 'skel/forgejo_actions/contest.yaml').read_text()
contest_workflow = substitute(contest_workflow_source, locals())
contest_workflow_target = forgejo / Path(f'workflows/{contest}/contest.yaml')
contest_workflow_target.parent.mkdir(parents=True, exist_ok=True)
contest_workflow_target.write_text(contest_workflow)

# Copy the problem-level workflows.
problem_workflow_source = (config.tools_root / 'skel/forgejo_actions/problem.yaml').read_text()
for problem_obj in problems:
problem = problem_obj.name
problem_path = contest_path / problem
problem_workflow = substitute(problem_workflow_source, locals())
problem_workflow_target = forgejo / Path(f'workflows/{contest}/{problem}.yaml')
problem_workflow_target.parent.mkdir(parents=True, exist_ok=True)
problem_workflow_target.write_text(problem_workflow)
10 changes: 10 additions & 0 deletions bin/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,12 @@ def build_parser():
'gitlabci', parents=[global_parser], help='Print a list of jobs for the given contest.'
)

subparsers.add_parser(
'forgejo_actions',
parents=[global_parser],
help='Setup Forgejo Actions workflows in .forgejo.',
)

exportparser = subparsers.add_parser(
'export', parents=[global_parser], help='Export the problem or contest to DOMjudge.'
)
Expand Down Expand Up @@ -937,6 +943,10 @@ def run_parsed_arguments(args):
skel.create_gitlab_jobs(contest, problems)
return

if action == 'forgejo_actions':
skel.create_forgejo_actions(contest, problems)
return

if action == 'skel':
skel.copy_skel_dir(problems)
return
Expand Down
25 changes: 25 additions & 0 deletions doc/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This lists all subcommands and their most important options.
- [`bt skel [--skel SKEL] directory [directory ...]`](#skel)
- [`bt rename_problem [problemname]`](#rename_problem)
- [`bt gitlabci`](#gitlabci)
- [`bt forgejo_actions`](#forgejo_actions)
- Exporting
- [`bt samplezip`](#samplezip)
- [`bt zip [--skip] [--force] [--kattis] [--no-solutions]`](#zip)
Expand Down Expand Up @@ -459,6 +460,30 @@ We use the following configuration for the gitlab runners:
"/tmp" = "rw,exec"
```

## `forgejo_actions`

`bt forgejo_actions` writes Forgejo Actions workflows for the current contest to
the `.forgejo` directory in the root of the git repository.
When there are multiple contests, run `bt forgejo_actions` once for each
contest (either in the contest directory, or by passing `--contest <contest>`).

The generated workflows are similar to those for `bt gitlabci` described above.

For smooth operation, use the following in the forgejo runner `config.yaml` to
increase the memory limit of the container and mount `/tmp` to memory.
```
container:
options: --memory=4g --memory-swap=4g --tmpfs /tmp:exec
```
and use the following label in `.runner`:
```json
{
"labels": [
"bapctools-docker:docker://ragnargrootkoerkamp/bapctools"
]
}
```

# Exporting

## `samplezip`
Expand Down
25 changes: 25 additions & 0 deletions skel/forgejo_actions/contest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: {%contest%} PDFs
on:
push:
branches:
- master
paths:
- {%contest_path%}/*/problem_statement/**
jobs:
build_pdfs:
name: {%contest%} PDFs
runs-on: bapctools-docker
steps:
- uses: actions/checkout@v4
- uses: ./.forgejo/actions/setup
- run: |
./bt pdf --cp --error --no-bar --contest {%contest_path%}
./bt solutions --cp --error --no-bar --contest {%contest_path%}
- uses: actions/upload-artifact@v3
with:
name: pdfs
path: |
{%contest_path%}/contest*.pdf
{%contest_path%}/solution*.pdf
retention-days: 7
18 changes: 18 additions & 0 deletions skel/forgejo_actions/problem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: {%problem_path%}
on:
push:
branches:
- master
paths:
- {%problem_path%}/**
- "!{%problem_path%}/problem_statement/**"
- "!{%problem_path%}/attachments/**"
jobs:
verify:
name: Verify {%problem%}
runs-on: bapctools-docker
steps:
- uses: actions/checkout@v4
- uses: ./.forgejo/actions/setup
- run: |
./bt all --cp --error --no-bar --force --jobs 0 --problem {%problem_path%}
8 changes: 8 additions & 0 deletions skel/forgejo_actions/setup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Setup BAPCtools
runs:
using: "composite"
steps:
- name: update BAPCtools
run: |
git -C /opt/hostedtoolcache/BAPCtools pull --ff-only || git clone https://github.com/RagnarGrootKoerkamp/BAPCtools.git /opt/hostedtoolcache/BAPCtools
ln -s /opt/hostedtoolcache/BAPCtools/bin/tools.py bt

0 comments on commit f8ff15c

Please sign in to comment.