Skip to content

Commit

Permalink
Add continuous integration via Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
agarciadom committed May 23, 2024
1 parent bb4d292 commit 8875525
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 21 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Java CI with Gradle

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

jobs:
build:
name: Native build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '17'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle Wrapper
run: ./gradlew build nativeCompile nativeTest
- name: Upload binary
uses: actions/upload-artifact@v4
with:
name: ecore2emfatic-${{ matrix.os }}
path: build/native/nativeCompile/ecore2emfatic*
29 changes: 29 additions & 0 deletions .github/workflows/release-jar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Github Packages Release Builds
on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: github
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle
run: ./gradlew build
- name: Publish package
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/release-native.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Native Release Builds
on:
push:
tags: [ "[0-9]+.[0-9]+.[0-9]+" ]

jobs:
build:
name: Native release build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '17'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
- name: Build with Gradle Wrapper
run: ./gradlew build nativeCompile nativeTest
- name: Upload release asset (Unix)
if: ${{ matrix.os != 'windows-latest' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
zip -j ${{ matrix.os }}-ecore2emfatic.zip build/native/nativeCompile/ecore2emfatic*
gh release upload $GITHUB_REF_NAME ${{ matrix.os }}-ecore2emfatic.zip
- name: Upload release asset (Windows)
if: ${{ matrix.os == 'windows-latest' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Compress-Archive -Path build/native/nativeCompile/ecore2emfatic* -DestinationPath ${{ matrix.os }}-ecore2emfatic.zip
gh release upload ${{ github.ref_name }} ${{ matrix.os }}-ecore2emfatic.zip
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ It is recommended to use [SDKMAN](https://sdkman.io/) for installing and managin
To produce Emfatic sources from an `.ecore` file, using the all-in-one JAR file in `build/libs/*-all.jar`:

```sh
java -jar path/to/Ecore2Emfatic-VERSION-all.jar path/to/your.ecore
java -jar path/to/ecore2emfatic-VERSION-all.jar path/to/your.ecore
```

When using one of the native binaries, this can be simplified to:

```sh
path/to/Ecore2Emfatic path/to/your.ecore
path/to/ecore2emfatic path/to/your.ecore
```

## Using native binaries as a Git filter
Expand All @@ -34,13 +34,13 @@ In order to compute differences between `.ecore` file versions using a Git `text
In Linux/Mac:

```sh
cp build/native/nativeCompile/Ecore2Emfatic /folder/in/PATH
cp build/native/nativeCompile/ecore2emfatic /folder/in/PATH
```

You will then need to define the `ecore` differencing algorithm:

```sh
git config --global diff.ecore.textconv Ecore2Emfatic
git config --global diff.ecore.textconv ecore2emfatic
```

You can then use this conversion from any Git repository, by adding a `.gitattributes` file to its root folder with this content:
Expand Down Expand Up @@ -71,18 +71,18 @@ index 84da8c9..f611dd1 100644
If your `.ecore` files import other metamodels through URIs, you can provide mappings from URIs to specific `.ecore` files or folders via the `--from` and `--to` options:

```sh
path/to/Ecore2Emfatic --from platform:/resource --to path/to/base/folder your.ecore
path/to/ecore2emfatic --from platform:/resource --to path/to/base/folder your.ecore
```

You can specify multiple pairs of `--from` and `--to` options, as in:

```sh
path/to/Ecore2Emfatic --from A --to B --from C --to D your.ecore
path/to/ecore2emfatic --from A --to B --from C --to D your.ecore
```

If you are using this tool as a `textconv` filter via Git, you would need to provide these options in your repository's configuration.
For example:

```sh
git config diff.ecore.textconv "Ecore2Emfatic --from A --to B"
git config diff.ecore.textconv "ecore2emfatic --from A --to B"
```
23 changes: 19 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "4.0.4"
id("maven-publish")
}

version = "0.1"
version = "0.1.0"
group = "org.eclipse.emfatic.cli"

repositories {
Expand All @@ -18,7 +19,6 @@ dependencies {
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("org.eclipse.emfatic:org.eclipse.emfatic.core:1.1.0")
implementation("org.eclipse.platform:org.eclipse.core.resources:3.13.700")
testImplementation('org.hamcrest:hamcrest:2.2')
runtimeOnly("ch.qos.logback:logback-classic")
}

Expand All @@ -38,5 +38,20 @@ micronaut {
}
}



publishing {
publications {
library(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/epsilonlabs/ecore2emfatic-cli"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

rootProject.name="Ecore2Emfatic"
rootProject.name="ecore2emfatic"

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
EStringToStringMapEntryImpl[].class,
ETypeParameter[].class
})
@Command(name = "Ecore2Emfatic", description = "Generates Emfatic sources from an .ecore file", mixinStandardHelpOptions = true)
@Command(name = "ecore2emfatic", description = "Generates Emfatic sources from an .ecore file", mixinStandardHelpOptions = true)
public class Ecore2EmfaticCommand implements Runnable {

static class URIMapping {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Tue May 21 17:03:57 BST 2024
micronaut.application.name=ecore2Emfatic
micronaut.application.name=ecore2emfatic
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import io.micronaut.configuration.picocli.PicocliRunner;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.env.Environment;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
Expand All @@ -29,12 +28,17 @@ public void testStandaloneMetamodel() throws Exception {
try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {
String[] args = new String[] { "src/test/resources/OO.ecore" };
PicocliRunner.run(Ecore2EmfaticCommand.class, ctx, args);
assertThat("Should see a PackageableElement in the output",
baos.toString(), containsString("PackageableElement"));
assertContains("Should see a PackageableElement in the output", baos.toString(), "PackageableElement");
}
}

@Test
private void assertContains(String reason, String text, String substring) {
if (!text.contains(substring)) {
fail(String.format("%s, but did not contain '%s':\n%s", reason, substring, text));
}
}

@Test
public void testMetamodelWithPlatformImport() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
Expand All @@ -46,8 +50,8 @@ public void testMetamodelWithPlatformImport() throws Exception {
"src/test/resources/platformImport/example2/ColoredTree.ecore"
};
PicocliRunner.run(Ecore2EmfaticCommand.class, ctx, args);
assertThat("Should see 'extends Trees.Tree' in the output",
baos.toString(), containsString("extends Trees.Tree"));
assertContains("Should see 'extends Trees.Tree' in the output",
baos.toString(), "extends Trees.Tree");
}
}
}

0 comments on commit 8875525

Please sign in to comment.