From 96932713ddd004bccab38fb6fd6ca48f64a1d82c Mon Sep 17 00:00:00 2001 From: Ennio Visconti Date: Tue, 11 Jul 2023 13:52:05 +0200 Subject: [PATCH] ci: updated deployment process --- .github/workflows/publish-java.yml | 29 ---- .github/workflows/publish-python.yml | 38 ------ .github/workflows/publish.yml | 124 ++++++++++++++++++ README.md | 11 ++ ...o.github.moonlightsuite.publish.gradle.kts | 6 +- build-logic/releases/.nyx.json | 87 ++++++++++++ build-logic/releases/changelog.hbs | 23 ++++ script/build.gradle.kts | 14 +- 8 files changed, 259 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/publish-java.yml delete mode 100644 .github/workflows/publish-python.yml create mode 100644 .github/workflows/publish.yml create mode 100644 build-logic/releases/.nyx.json create mode 100644 build-logic/releases/changelog.hbs diff --git a/.github/workflows/publish-java.yml b/.github/workflows/publish-java.yml deleted file mode 100644 index 60859ab3..00000000 --- a/.github/workflows/publish-java.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Publish package to GitHub Packages -name: publish package -on: - workflow_dispatch: -# release: -# types: [created] - -jobs: - publish: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v2 - - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'adopt' - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Publish Github Package with Gradle - run: ./gradlew publish --info - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish-python.yml b/.github/workflows/publish-python.yml deleted file mode 100644 index d1ae2851..00000000 --- a/.github/workflows/publish-python.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Publish package to GitHub Packages -name: Publish on PyPi -on: - workflow_dispatch: - release: - types: [created] - -jobs: - publish: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v2 - with: - java-version: '17' - distribution: 'adopt' - cache: gradle - - - name: Build releasable python package - run: ./gradlew :python:distribute - - - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - run: pipx install poetry - - - name: Publishing setup - run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} - working-directory: ./python - - - name: Build & deploy package - run: poetry publish --build - working-directory: ./python diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..2f919353 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,124 @@ +name: Publish on Github & Maven Central +on: [ push ] + +jobs: + infer-version: + name: Computing a new version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.nyx-infer.outputs.version }} + newRelease: ${{ steps.nyx-infer.outputs.newRelease }} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Run nyx Infer + id: nyx-infer + uses: mooltiverse/nyx-github-action@main + with: + command: 'infer' + configurationFile: 'build-logic/releases/.nyx.json' + resume: 'true' + - name: Run nyx Make + uses: mooltiverse/nyx-github-action@main + with: + command: 'make' + configurationFile: 'build-logic/releases/.nyx.json' + resume: 'true' + + publish-version: + if: needs.infer-version.outputs.newRelease == 'true' + name: Publishing a new version + runs-on: ubuntu-latest + needs: infer-version + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: adopt + cache: gradle + - name: Run gradle publish + run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-configuration-cache + env: + ORG_GRADLE_PROJECT_projectVersion: ${{ needs.infer-version.outputs.version }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_PASSWORD }} + - name: Nyx publish + uses: mooltiverse/nyx-github-action@main + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NYX_RELEASE_TYPES_PUBLICATION_SERVICES: 'GITHUB' + NYX_SERVICES_GITHUB_NAME: 'GITHUB' + NYX_SERVICES_GITHUB_TYPE: 'GITHUB' + NYX_SERVICES_GITHUB_OPTIONS_AUTHENTICATION_TOKEN: "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}" + NYX_SERVICES_GITHUB_OPTIONS_REPOSITORY_NAME: 'webmonitor' + NYX_SERVICES_GITHUB_OPTIONS_REPOSITORY_OWNER: 'ennioVisco' + with: + command: 'publish' + configurationFile: 'build-logic/releases/.nyx.json' + resume: 'true' + + publish-python: + runs-on: ubuntu-latest + needs: infer-version + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'adopt' + cache: gradle + + - name: Find and Replace + uses: jacobtomlinson/gha-find-replace@v3 + with: + find: version = "\d+.\d+.\d+(-.+)?" + replace: version = "${{ needs.infer-version.outputs.version }}" + include: "python/pyproject.toml" + + - name: Build releasable python package + run: ./gradlew :python:distribute + + - uses: actions/setup-python@v4 + with: + python-version: '3.8' + - run: pipx install poetry + + - name: Publishing setup + run: poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} + working-directory: ./python + + - name: Build & deploy package + run: poetry publish --build + working-directory: ./python + + update-readme: + if: github.ref_name == 'master' + name: Updating README.md + runs-on: ubuntu-latest + needs: [ publish-version, infer-version ] + steps: + - uses: actions/checkout@v3 + - name: Find and Replace + uses: jacobtomlinson/gha-find-replace@v3 + with: + find: io.github.moonlightsuite:moonlight-engine:\d+.\d+.\d+(-SNAPSHOT)? + replace: io.github.moonlightsuite:moonlight-engine:${{ needs.infer-version.outputs.version }} + include: "README.md" + - uses: fregante/setup-git-user@v2 + - name: Push changes + run: | + git add README.md + git commit -m "Updated README.md instructions with new package version" || true + git push || true diff --git a/README.md b/README.md index 53f8199a..c75709e1 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,15 @@ The tool supports two type of semantics (satisfaction), the Boolean and the quan Choosing the Boolean semantics the tool returns a Boolean satisfaction signal, that tells at each time in each location if the trajectory satisfies or not the property, choosing instead the Quantitative semantics the tool returns a real-value signal that corresponds to the value of satisfaction of the property. --> +### Usage as Maven package + +To use it as a maven package, just include the following line in your `build.gradle.kts`: + +```kts +implementation("io.github.moonlightsuite:moonlight-engine:0.2.0") +``` + +Check on [Maven Central](https://central.sonatype.com/artifact/io.github.moonlightsuite/moonlight-engine/) for alternative build tools ( +e.g. Maven). + For more information, please visit our [Wiki](https://github.com/MoonLightSuite/MoonLight/wiki) diff --git a/build-logic/java-library/src/main/kotlin/io.github.moonlightsuite.publish.gradle.kts b/build-logic/java-library/src/main/kotlin/io.github.moonlightsuite.publish.gradle.kts index 28fea35f..86be7f26 100644 --- a/build-logic/java-library/src/main/kotlin/io.github.moonlightsuite.publish.gradle.kts +++ b/build-logic/java-library/src/main/kotlin/io.github.moonlightsuite.publish.gradle.kts @@ -6,7 +6,11 @@ plugins { } val projectVersion: String = try { - providers.gradleProperty("projectVersion").get() + val ver = providers.gradleProperty("projectVersion").get() + if (ver.contains("-")) { + println("WARNING: publishing snapshot version") + "${ver.split("-")[0]}-SNAPSHOT" + } else ver } catch (e: IllegalStateException) { println("ERROR - Unable to find version: ${e.message}") "0.1.0-SNAPSHOT" diff --git a/build-logic/releases/.nyx.json b/build-logic/releases/.nyx.json new file mode 100644 index 00000000..7e740661 --- /dev/null +++ b/build-logic/releases/.nyx.json @@ -0,0 +1,87 @@ +{ + "preset": "simple", + "changelog": { + "path": "build-logic/releases/CHANGELOG.md", + "template": "build-logic/releases/changelog.hbs", + "sections": { + ":sparkles: Added": "^feat$", + ":bug: Fixed": "^fix$", + ":zap: Improved": "^perf$", + ":hammer: Tooling": "^(build|ci)$", + ":memo: Documentation": "^docs$" + }, + "substitutions": { + "(?m)#([0-9]+)(?s)": "[#%s](https://github.com/enniovisco/webmonitor/issues/%s)" + } + }, + "git": { + "remotes": { + "origin": { + "authenticationMethod": "USER_PASSWORD", + "user": "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}", + "password": "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}" + } + } + }, + "initialVersion": "0.2.0", + "releasePrefix": "v", + "releaseTypes": { + "enabled": [ + "mainline", + "internal" + ], + "publicationServices": [ + "github" + ], + "remoteRepositories": [ + "origin" + ], + "items": { + "mainline": { + "collapseVersions": false, + "filterTags": "^({{configuration.releasePrefix}})?([0-9]\\d*)\\.([0-9]\\d*)\\.([0-9]\\d*)$", + "gitCommit": "false", + "gitCommitMessage": "Release version {{version}}", + "gitPush": "true", + "gitTag": "true", + "gitTagMessage": "Tag version {{version}}", + "matchBranches": "^(master|main)$", + "matchEnvironmentVariables": { + "CI": "^true$" + }, + "matchWorkspaceStatus": "CLEAN", + "publish": "true", + "versionRangeFromBranchName": false + }, + "internal": { + "collapseVersions": true, + "collapsedVersionQualifier": "beta", + "description": "{{#replace from=\"# Changelog\" to=\"\"}}{{#fileContent}}CHANGELOG.md{{/fileContent}}{{/replace}}", + "gitCommit": "false", + "gitPush": "false", + "gitTag": "false", + "publish": "true", + "identifiers": [ + { + "position": "PRE_RELEASE", + "qualifier": "beta" + } + ], + "versionRangeFromBranchName": false + } + } + }, + "services": { + "github": { + "type": "GITHUB", + "options": { + "AUTHENTICATION_TOKEN": "{{#environmentVariable}}GH_TOKEN{{/environmentVariable}}", + "REPOSITORY_NAME": "webmonitor", + "REPOSITORY_OWNER": "enniovisco" + } + } + }, + "summaryFile": "build-logic/releases/.nyx-summary.txt", + "stateFile": "build-logic/releases/.nyx-state.json", + "verbosity": "INFO" +} diff --git a/build-logic/releases/changelog.hbs b/build-logic/releases/changelog.hbs new file mode 100644 index 00000000..8d7bd3a1 --- /dev/null +++ b/build-logic/releases/changelog.hbs @@ -0,0 +1,23 @@ +# Changelog + +{{#releases}} +## {{name}} ({{date}}) + +{{#sections}} +### {{name}} + +{{#commits}} +* [[{{#short5}}{{sha}}{{/short5}}](https://github.com/enniovisco/webmonitor/commit/{{sha}})] {{message.shortMessage}} ({{authorAction.identity.name}}) + +{{/commits}} +{{^commits}} +No changes. +{{/commits}} +{{/sections}} +{{^sections}} +No changes. +{{/sections}} +{{/releases}} +{{^releases}} +No releases. +{{/releases}} diff --git a/script/build.gradle.kts b/script/build.gradle.kts index 5a33b8d4..ea0dbf17 100644 --- a/script/build.gradle.kts +++ b/script/build.gradle.kts @@ -17,14 +17,18 @@ dependencies { runtimeOnly("org.antlr:antlr4-runtime:4.8") } +tasks.generateGrammarSource { + arguments.addAll(listOf("-visitor", "-long-messages")) +} + tasks.build { dependsOn(tasks.generateGrammarSource) } -//tasks.sourcesJar { -// dependsOn(tasks.generateGrammarSource) -//} +tasks.kotlinSourcesJar { + dependsOn(tasks.generateGrammarSource) +} -tasks.generateGrammarSource { - arguments.addAll(listOf("-visitor", "-long-messages")) +tasks.dokkaHtml { + dependsOn(tasks.generateGrammarSource) }