#!/usr/bin/env bash # Converts a repository's committed .werkator.yml into Forgejo Actions workflows # (RFC 0006, step 1), one workflow per build definition that triggers on its own, # its follow-ups as jobs with `needs`. What has no workflow counterpart is # written as a comment in the workflow and listed on stderr. # # Usage: # tools/werkator-to-forgejo [REPO] [--stdout] [--strict] [--output-dir DIR] [--runs-on LABEL] # # REPO the target repository, or any directory inside it (default: .); # the .werkator.yml in its root is converted, and the workflows are # written into it, below .forgejo/workflows/ # --output-dir where to write them instead, relative to the repository root, # e.g. .gitea/workflows for a Gitea forge # --stdout print the workflows instead of writing them # --strict write nothing and exit 1 when anything cannot be converted # --runs-on the runner label of every job (default: docker) # # Only the committed file is read: the .git layers, the applied fragment and # ~/.werkator.yml are runner and instance configuration in Forgejo terms, and # they hold the secrets. # # The conversion is Werkator's `export:forgejo` command, so it binds the file # exactly as Werkator does. It runs the `werkator` named by WERKATOR_BIN, else # the one on PATH, else the jar of this checkout (built when missing). set -euo pipefail if [ -n "${WERKATOR_BIN:-}" ]; then werkator=("$WERKATOR_BIN") elif command -v werkator >/dev/null 2>&1; then werkator=(werkator) else here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" jar="$here/build/libs/werkator.jar" if [ ! -f "$jar" ]; then echo "==> Building $jar" >&2 (cd "$here" && ./gradlew -q bootJar) >&2 fi werkator=(java -jar "$jar") fi exec "${werkator[@]}" export:forgejo "$@"