Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/docker/codegen-tests/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM eclipse-temurin:11-jdk-jammy

WORKDIR /test

RUN apt-get update && apt-get install -y curl && \
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

CMD ["bash", "-c", "echo 'Testing environment...' && javac -version && node --version && echo '✅ Java + Node.js ready!'"]
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image CMD only prints tool versions and never runs test-java.sh, so docker run concerto-java-test won't execute any Java code generation/compilation checks. Copy the test script into the image and set ENTRYPOINT/CMD to run it (or remove the CMD and have the workflow run the script explicitly).

Suggested change
CMD ["bash", "-c", "echo 'Testing environment...' && javac -version && node --version && echo '✅ Java + Node.js ready!'"]
COPY test-java.sh /test/test-java.sh
RUN chmod +x /test/test-java.sh
CMD ["bash", "/test/test-java.sh"]

Copilot uses AI. Check for mistakes.
39 changes: 39 additions & 0 deletions .github/docker/codegen-tests/java/test-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -e

echo "Testing Java code generation..."

mkdir -p /test/output
cd /test/output

Comment on lines +6 to +8
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script writes under /test (a host-mounted directory in the workflow) while the container runs as root by default. That will create root-owned files (/test/output, compiled .class, potentially node_modules) in the GitHub Actions workspace and can break later steps/cleanup. Prefer writing to a container-only temp dir (e.g., under /tmp) or run the container with --user to match the runner UID/GID.

Copilot uses AI. Check for mistakes.
cat > test.cto << 'EOF'
namespace test@1.0.0

concept Person {
o String name
o Integer age
}
EOF

echo "Generated test CTO file:"
cat test.cto

cd /test
npm install
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm install is non-reproducible compared to npm ci and will also re-run lifecycle scripts and potentially mutate package-lock.json/node_modules in the mounted workspace. For CI-style execution, use npm ci (or skip install entirely if the workflow already ran npm ci and you rely on the mounted node_modules).

Suggested change
npm install
npm ci

Copilot uses AI. Check for mistakes.

echo "Generating Java code..."
node -e "
const { CodeGen } = require('@accordproject/concerto-codegen');
const fs = require('fs');
const cto = fs.readFileSync('/test/output/test.cto', 'utf8');
const codeGen = new CodeGen(cto);
const javaCode = codeGen.generate('Java');
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format key in this repo is lowercase (java), not 'Java' (see lib/codegen/codegen.js formats). Using 'Java' will fail even once the generator call is corrected.

Suggested change
const javaCode = codeGen.generate('Java');
const javaCode = codeGen.generate('java');

Copilot uses AI. Check for mistakes.
fs.writeFileSync('/test/output/Person.java', javaCode);
Comment on lines +27 to +31
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeGen exported by @accordproject/concerto-codegen is not a constructor (it exports visitor classes / a formats map). new CodeGen(cto) will throw at runtime. Use the supported visitor-based flow (e.g., ModelManager.accept(new CodeGen.formats.java(), { fileWriter, ... })) to generate output.

Suggested change
const fs = require('fs');
const cto = fs.readFileSync('/test/output/test.cto', 'utf8');
const codeGen = new CodeGen(cto);
const javaCode = codeGen.generate('Java');
fs.writeFileSync('/test/output/Person.java', javaCode);
const { ModelManager } = require('@accordproject/concerto-core');
const fs = require('fs');
const path = require('path');
const cto = fs.readFileSync('/test/output/test.cto', 'utf8');
const modelManager = new ModelManager();
modelManager.addModelFile(cto, 'test.cto');
const outputDir = '/test/output';
const fileWriter = {
currentFile: null,
files: {},
openFile: function (fileName) {
this.currentFile = fileName;
this.files[fileName] = [];
},
writeLine: function (line) {
if (!this.currentFile) {
throw new Error('No file is currently open for writing.');
}
this.files[this.currentFile].push(line);
},
closeFile: function () {
if (!this.currentFile) {
return;
}
const fileName = this.currentFile;
const content = this.files[fileName].join('\n') + '\n';
const fullPath = path.join(outputDir, fileName);
fs.writeFileSync(fullPath, content, 'utf8');
this.currentFile = null;
}
};
modelManager.accept(new CodeGen.formats.java(), { fileWriter });

Copilot uses AI. Check for mistakes.
"

echo "Compiling generated Java code..."
cd /test/output
javac *.java

echo "Java code generation and compilation successful!"
ls -la *.class
35 changes: 35 additions & 0 deletions .github/workflows/test-java-codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Java Code Generation

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test-java-codegen:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install dependencies
run: npm ci

- name: Build project
run: npm run build

- name: Build Docker image for Java testing
run: |
docker build -t concerto-java-test -f .github/docker/codegen-tests/java/Dockerfile .
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docker build context is set to . after npm ci/npm run build, which will include node_modules and other artifacts in the build context upload even though the Dockerfile doesn't use them. Consider using .github/docker/codegen-tests/java as the build context (or add a .dockerignore / reorder steps) to avoid slow, large context transfers in CI.

Suggested change
docker build -t concerto-java-test -f .github/docker/codegen-tests/java/Dockerfile .
docker build -t concerto-java-test -f .github/docker/codegen-tests/java/Dockerfile .github/docker/codegen-tests/java

Copilot uses AI. Check for mistakes.

- name: Test Java code generation in Docker
run: |
docker run --rm \
-v "$(pwd):/test" \
concerto-java-test
Comment on lines +14 to +35
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steps: is followed by list items that are not indented under it, which makes this workflow YAML invalid and prevents the job from running. Indent the - uses: / - name: entries two more spaces so they are children of steps:.

Suggested change
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Build Docker image for Java testing
run: |
docker build -t concerto-java-test -f .github/docker/codegen-tests/java/Dockerfile .
- name: Test Java code generation in Docker
run: |
docker run --rm \
-v "$(pwd):/test" \
concerto-java-test
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Build Docker image for Java testing
run: |
docker build -t concerto-java-test -f .github/docker/codegen-tests/java/Dockerfile .
- name: Test Java code generation in Docker
run: |
docker run --rm \
-v "$(pwd):/test" \
concerto-java-test

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docker run executes the image's default CMD, but the Dockerfile currently only prints versions and exits—so no Java code generation/compilation is actually tested. Either set the image entrypoint/CMD to run the test script, or invoke the script explicitly in this step (e.g., docker run ... bash /test/.github/docker/codegen-tests/java/test-java.sh).

Suggested change
concerto-java-test
concerto-java-test \
bash /test/.github/docker/codegen-tests/java/test-java.sh

Copilot uses AI. Check for mistakes.
Loading