mirror of
https://hub.psychoinformatics.de/actions/process-upload.git
synced 2026-10-07 01:16:18 +00:00
87 lines
3.5 KiB
Markdown
87 lines
3.5 KiB
Markdown
# Forgejo Action for processing uploaded files
|
|
|
|
Moves one uploaded file to a target location, optionally normalizes it, removes the original upload, and commits and pushes the resulting changes.
|
|
|
|
## Parameters
|
|
|
|
The following parameters can be given via the `with` key. Example:
|
|
|
|
```yaml
|
|
- name: Ingest upload
|
|
uses: https://hub.psychoinformatics.de/actions/process-upload@v1
|
|
with:
|
|
file-pattern: "*.csv"
|
|
target-file: data.csv
|
|
```
|
|
|
|
| Name | Default | Description |
|
|
|---|---|---|
|
|
| `source-dir` | `ingest` | Directory containing pending uploads. |
|
|
| `file-pattern` | `*` | Filename pattern used to find uploads, such as `*.csv` or `*.xlsx`. |
|
|
| `source-file` | Empty | Optional exact repository-relative source path. If omitted, exactly one matching file must exist directly under `source-dir`. |
|
|
| `target-file` | — | Required repository-relative destination path. |
|
|
| `fetch-command` | Empty | Optional shell command used to materialize the source file before processing. The source path is available as `$INPUT_FILE`. Useful with git-annex. |
|
|
| `normalizer` | Empty | Optional shell command that reads `$INPUT_FILE` and writes `$OUTPUT_FILE`. If omitted, the source file is moved unchanged. |
|
|
| `commit-and-push` | `true` | Commit and push the resulting changes. Set to `false` to handle this in the calling workflow. When enabled uses `git add -A`, hence the worktree should be free of unrelated changes before the action is applied. |
|
|
| `commit-message` | `chore: process uploaded file` | Commit subject used when `commit-and-push` is enabled. |
|
|
| `commit-user-name` | `Workflow runner` | Git commit author name. |
|
|
| `commit-user-email` | Automatically generated | Git commit author email. |
|
|
|
|
The action ignores `.gitkeep` and `.gitignore` when discovering uploads.
|
|
|
|
A normalizer is workflow-provided shell code. It must read the source file from `$INPUT_FILE` and create the output file at `$OUTPUT_FILE`.
|
|
|
|
## Standard usage: move an unmodified CSV
|
|
|
|
This workflow step moves one CSV upload from `ingest/` to `data.csv`, removes the original upload, and commits and pushes the result.
|
|
|
|
```yaml
|
|
- name: Process CSV upload
|
|
uses: https://hub.psychoinformatics.de/actions/process-upload@v1
|
|
with:
|
|
source-dir: ingest
|
|
file-pattern: "*.csv"
|
|
target-file: data.csv
|
|
commit-message: "chore: ingest CSV update"
|
|
```
|
|
|
|
## Standard usage: convert XLSX to TSV
|
|
|
|
This workflow step retrieves one git-annex-backed XLSX upload, converts it to TSV, removes the original upload, and commits and pushes the result. Software availability and credentials must be establish beforehand.
|
|
|
|
```yaml
|
|
- name: Process XLSX upload
|
|
uses: https://hub.psychoinformatics.de/actions/process-upload@v1
|
|
with:
|
|
source-dir: orig
|
|
file-pattern: "*.xlsx"
|
|
target-file: id.tsv
|
|
fetch-command: |
|
|
git annex get -- "$INPUT_FILE"
|
|
normalizer: |
|
|
uv run \
|
|
https://example.org/actions/xlsx-to-tsv/convert.py \
|
|
"$INPUT_FILE" \
|
|
"$OUTPUT_FILE"
|
|
commit-message: "Update TSV-formatted table from upload"
|
|
```
|
|
|
|
## Handling commits separately
|
|
|
|
Set `commit-and-push` to `false` when the calling workflow needs custom commit or push behavior:
|
|
|
|
```yaml
|
|
- name: Process upload
|
|
uses: https://hub.psychoinformatics.de/actions/process-upload@v1
|
|
with:
|
|
source-dir: ingest
|
|
file-pattern: "*.csv"
|
|
target-file: data.csv
|
|
commit-and-push: "false"
|
|
```
|
|
|
|
When disabled, the action only modifies the worktree. The calling workflow is responsible for staging, committing, and pushing the changes.
|
|
|
|
## License
|
|
|
|
MIT
|