diff --git a/.github/scripts/regenerate.sh b/.github/scripts/regenerate.sh new file mode 100755 index 000000000..fe3644c8d --- /dev/null +++ b/.github/scripts/regenerate.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash +# Checks that every tracked MWE2 workflow has an Eclipse launch, then runs the workflows headless, without Eclipse, +# except those listed below. In Eclipse, run a workflow's launch instead; this script must reproduce its output. +# Build first, on JDK 21, and again after changing a grammar or generator: +# ./mvnw install -DskipTests -f ddk-parent/pom.xml -pl ":ddk-target,$(.github/scripts/regenerate.sh --owners)" -am -Dtycho.baseline=disable -Dtycho.baseline.replace=none +# Arguments are passed to Maven, e.g. -Dmaven.repo.local=...; --owners prints the owning bundles as a -pl list, --list the workflows it runs. +set -euo pipefail + +# Not standalone workflows. +EXCLUDE=( + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/Ddk.mwe2 # only chains the other workflows + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/CommonXbase.mwe2 # shared module of the language workflows + com.avaloq.tools.ddk.check.test.runtime/src/com/avaloq/tools/ddk/check/generator/TestLanguageGeneratorMWE.mwe2 # needs targetDir and modelPath +) + +# Workflows whose committed output still differs from what they generate, with the issue that fixes each. +KNOWN_DRIFT=( + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/GenerateExport.mwe2 # #1671 + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/GenerateFormat.mwe2 # #1671 + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/GenerateFormatterTestLanguage.mwe2 # #1671 + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/GenerateCheck.mwe2 # #1671 + com.avaloq.tools.ddk.workflow/src/com/avaloq/tools/ddk/workflow/GenerateCheckCfg.mwe2 # #1671 + com.avaloq.tools.ddk.sample.helloworld/src/com/avaloq/tools/ddk/sample/helloworld/GenerateHelloWorld.mwe2 # #1671 + com.avaloq.tools.ddk.check.test.runtime/src/com/avaloq/tools/ddk/check/GenerateTestLanguage.mwe2 # #1672 +) + +root=$(git rev-parse --show-toplevel) +cd "$root" + +# /, for every tracked workflow not listed above. +skip=" ${EXCLUDE[*]} ${KNOWN_DRIFT[*]-} " +tracked=" $(git ls-files '*.mwe2' | tr '\n' ' ') " +for wf in ${skip}; do + [[ $tracked == *" $wf "* ]] || { echo "regenerate.sh: listed workflow $wf is not tracked" >&2; exit 1; } +done +WORKFLOWS=() +while read -r wf; do + [[ $skip == *" $wf "* ]] || WORKFLOWS+=("$wf") +done < <(git ls-files '*.mwe2') + +# Every workflow, drifting or not, needs a tracked Eclipse launch: an MWE2 launch of its owning bundle whose +# argument is the workflow's path in that bundle or its module name. +launches=$(git ls-files -z '*.launch' | xargs -0 grep -l Mwe2LaunchConfigurationType) +missing=() +for wf in "${WORKFLOWS[@]}" ${KNOWN_DRIFT[@]+"${KNOWN_DRIFT[@]}"}; do + b=${wf%%/*} + module=$(sed -n 's/^module \([A-Za-z0-9_.]*\).*/\1/p' "$wf") + found= + while read -r l; do + [[ -n $l ]] && grep -q "PROJECT_ATTR\" value=\"$b\"" "$l" \ + && grep -q -e "PROGRAM_ARGUMENTS\" value=\"${wf#*/}\"" -e "PROGRAM_ARGUMENTS\" value=\"$module\"" "$l" && { found=1; break; } + done <<< "$launches" + [[ -n $found ]] || missing+=("$wf") +done +if (( ${#missing[@]} )); then + printf 'regenerate.sh: no Eclipse launch runs %s\n' "${missing[@]}" >&2 + exit 1 +fi + +bundles=() +for wf in "${WORKFLOWS[@]}"; do + b=${wf%%/*} + [[ " ${bundles[*]-} " == *" $b "* ]] || bundles+=("$b") +done + +projects=$(printf ',:%s' "${bundles[@]}") +if [[ ${1-} == --owners ]]; then + echo "${projects:1}" + exit 0 +fi +if [[ ${1-} == --list ]]; then + printf '%s\n' "${WORKFLOWS[@]}" + exit 0 +fi + +# All Maven runs happen before the workflows touch the tree (jgit.dirtyWorkingTree=error in CI). +tycho=$(sed -n 's:.*\(.*\).*:\1:p' ddk-parent/pom.xml) +./mvnw -f ddk-parent/pom.xml --batch-mode -pl "${projects:1}" "$@" \ + "org.eclipse.tycho.extras:tycho-dependency-tools-plugin:${tycho}:list-dependencies" + +# Classpath: owning bundle, third-party jars, DDK bundles from the reactor's target/classes, ANTLR patch. +for b in "${bundles[@]}"; do + # Not in a command substitution, so set -e stops the script on a missing list or unbuilt bundle. + { + echo "$root/$b/target/classes" + grep -v -e '\.source[-/_]' -e '-sources\.jar$' "$b/target/dependencies-list.txt" | while read -r jar; do + bsn=$(basename "$(dirname "$(dirname "$jar")")") + if [[ $bsn == com.avaloq.tools.ddk* ]]; then + [[ -d "$root/$bsn/target/classes" ]] || { echo "regenerate.sh: $bsn is not built" >&2; exit 1; } + echo "$root/$bsn/target/classes" + else + echo "$jar" + fi + done + echo "$root/com.avaloq.tools.ddk.workflow/antlr-generator-3.2.0-patch.jar" + } | awk '!seen[$0]++' | paste -sd: - > "$b/target/mwe2.cp" + printf -- '-cp "%s"\n' "$(<"$b/target/mwe2.cp")" > "$b/target/mwe2.args" +done + +failed=() +for wf in "${WORKFLOWS[@]}"; do + b=${wf%%/*} + echo "::group::${wf##*/}" + # Workflows resolve paths against rootPath = "..", so they run from the owning bundle's directory. + (cd "$root/$b" && "${JAVA_HOME:+$JAVA_HOME/bin/}java" -Xmx3g @target/mwe2.args org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher "${wf#*/}") || failed+=("$wf") + echo "::endgroup::" +done + +if (( ${#failed[@]} )); then + printf 'regenerate.sh: workflow failed: %s\n' "${failed[@]}" >&2 + exit 1 +fi diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 30f34c4ae..187a730c3 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -96,3 +96,38 @@ jobs: name: tycho-surefire-plugin path: com.avaloq.tools.ddk.*/target/work/data/.metadata/.log include-hidden-files: true + generated-sources: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Full history for Tycho's jgit build-qualifier, as in maven-verify. + fetch-depth: 0 + - name: Set up JDK 21 + uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0 + with: + distribution: 'temurin' + java-version: '21' + - name: Restore Maven dependency cache + # Path and key must mirror maven-verify and snapshot.yml exactly. + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-publish-${{ hashFiles('**/pom.xml', '**/*.target') }} + restore-keys: ${{ runner.os }}-maven-publish- + - name: Drop cached p2 metadata for the DDK update site + # See maven-verify. + run: rm -rf ~/.m2/repository/.cache/tycho/https/dsldevkit.github.io ~/.m2/repository/.cache/tycho/https/ddk.tools.avaloq.com + - name: Build the bundles owning the workflows + # Maven must finish before the workflows dirty the tree. + run: ./mvnw install -DskipTests -f ./ddk-parent/pom.xml -pl ":ddk-target,$(bash .github/scripts/regenerate.sh --owners)" -am --batch-mode -T 2 -Dtycho.baseline=disable -Dtycho.baseline.replace=none + - name: Regenerate sources + run: bash .github/scripts/regenerate.sh + - name: Fail on generated sources out of sync + run: | + git status --porcelain --untracked-files=all + if [ -n "$(git status --porcelain --untracked-files=all)" ]; then + git diff + echo "::error::Generated sources differ from their generators; run the workflow's .mwe2.launch in Eclipse (or .github/scripts/regenerate.sh) and commit the result." + exit 1 + fi diff --git a/AGENTS.md b/AGENTS.md index 4039ecacb..50b164836 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -145,6 +145,17 @@ These directories contain generated code - do not edit manually: xvfb-run ./mvnw verify -f ./ddk-parent/pom.xml -pl :com.avaloq.tools.ddk.xtext.test ``` +### Regenerating Sources +Regenerate in Eclipse: every tracked MWE2 workflow has an MWE2 launch (`git ls-files '*.launch'`); run it from the IDE and commit the result. Eclipse output is the reference: `.github/scripts/regenerate.sh` must reproduce it, and when the two differ, fix the script, not the committed files. + +`.github/scripts/regenerate.sh` fails if a workflow has no launch, then runs every tracked workflow without Eclipse, except those in its `EXCLUDE` (not standalone) and `KNOWN_DRIFT` (output not yet in sync, each with its issue) arrays; `--list` prints the ones it runs. The `generated-sources` job in `verify.yml` runs it and fails if the result differs from the committed files. The workflows read grammars and generators from `target/classes`, so build the owning bundles with `install` first, on JDK 21, and again after changing a grammar or generator. `install` writes DDK snapshots to the local Maven repository; add `-Dmaven.repo.local=...` to both commands to keep them out of `~/.m2`. Script arguments are passed to Maven: +```bash +./mvnw install -DskipTests -f ./ddk-parent/pom.xml -pl ":ddk-target,$(.github/scripts/regenerate.sh --owners)" -am -Dtycho.baseline=disable -Dtycho.baseline.replace=none +.github/scripts/regenerate.sh +git status +``` +A new workflow is checked automatically, and the job builds its owning bundle from `--owners`. Add to `KNOWN_DRIFT` only with an issue that removes the entry again. + ### Bumping Versions CI fails with "Only qualifier changed" when a published bundle or feature differs from the last release (`p2/releases/latest`) but keeps its version. 1. Changing a published bundle (one included in the features, incl. `test.core`, `test.ui`, `xtext.test.core`): its version on `master` must reflect the strongest change since the last release, so it is bumped at most once per level between releases, not once per PR. diff --git a/com.avaloq.tools.ddk.checkcfg.core/GenerateCheckCfg.mwe2.launch b/com.avaloq.tools.ddk.checkcfg.core/GenerateCheckCfg.mwe2.launch index 24f20b47c..14dc55f23 100644 --- a/com.avaloq.tools.ddk.checkcfg.core/GenerateCheckCfg.mwe2.launch +++ b/com.avaloq.tools.ddk.checkcfg.core/GenerateCheckCfg.mwe2.launch @@ -8,7 +8,7 @@ - - - + + + diff --git a/com.avaloq.tools.ddk.workflow/GenerateExport.mwe2.launch b/com.avaloq.tools.ddk.workflow/GenerateExport.mwe2.launch new file mode 100644 index 000000000..5fd4ba67f --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/GenerateExport.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/GenerateExpression.mwe2.launch b/com.avaloq.tools.ddk.workflow/GenerateExpression.mwe2.launch new file mode 100644 index 000000000..9c456b2e3 --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/GenerateExpression.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/GenerateFormat.mwe2.launch b/com.avaloq.tools.ddk.workflow/GenerateFormat.mwe2.launch new file mode 100644 index 000000000..ff67fae17 --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/GenerateFormat.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/GenerateFormatterTestLanguage.mwe2.launch b/com.avaloq.tools.ddk.workflow/GenerateFormatterTestLanguage.mwe2.launch new file mode 100644 index 000000000..585cef3e2 --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/GenerateFormatterTestLanguage.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/GenerateScope.mwe2.launch b/com.avaloq.tools.ddk.workflow/GenerateScope.mwe2.launch new file mode 100644 index 000000000..efa802c30 --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/GenerateScope.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/ModelInference.mwe2.launch b/com.avaloq.tools.ddk.workflow/ModelInference.mwe2.launch new file mode 100644 index 000000000..494f8214d --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/ModelInference.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/TypeModel.mwe2.launch b/com.avaloq.tools.ddk.workflow/TypeModel.mwe2.launch new file mode 100644 index 000000000..2062892a6 --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/TypeModel.mwe2.launch @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/com.avaloq.tools.ddk.workflow/pom.xml b/com.avaloq.tools.ddk.workflow/pom.xml new file mode 100644 index 000000000..15973243c --- /dev/null +++ b/com.avaloq.tools.ddk.workflow/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + + ddk-parent + com.avaloq.tools.ddk + 18.0.1-SNAPSHOT + ../ddk-parent + + 17.3.1-SNAPSHOT + com.avaloq.tools.ddk + com.avaloq.tools.ddk.workflow + eclipse-plugin + diff --git a/ddk-parent/pom.xml b/ddk-parent/pom.xml index e7ccb18f0..4c8506ada 100644 --- a/ddk-parent/pom.xml +++ b/ddk-parent/pom.xml @@ -134,6 +134,7 @@ ../com.avaloq.tools.ddk.sample.helloworld.ui.test ../com.avaloq.tools.ddk.typesystem ../com.avaloq.tools.ddk.typesystem.test + ../com.avaloq.tools.ddk.workflow @@ -238,7 +239,11 @@ jgit ${jgit.dirtyWorkingTree} - .project + + + .project + *.launch + 'v'yyyyMMdd-HHmm