Skip to content

Commit

Permalink
Automate build with maven
Browse files Browse the repository at this point in the history
## Functionality of the build system:

Run the build with `mvn install`

- check RDF source formatting
   - fail build if there are violations
   - enable to fix formatting via `mvn spotless:apply`
- remove all `qudt:applicableUnits` triples from the quantitykinds file
- copy all relevant sources to `target/dist`
- replace the version placeholder, `$$QUDT_VERSION$$` everywhere in `target/dist`
- infer `qudt:applicableUnits` by applying `src/build/inference/inferApplicableUnits.ttl` and
  add those triples to the quantitykinds file in `target/dist`
- evaluate all SHACL shapes on the build result in `target/dist` and fail the build if
  there are violations

Profile `zip` builds the release zip:

`mvn -Pzip install`

## Github Actions

Github actions are defined in `.github/workflows`:
- maven.yml - runs the build upon push to a PR or when a PR is merged to `main`. In the
  latter case, the action makes a github release `snapshot` and a tag with that name,
  which will overwrite the previous such snapshot release
- release.yml - manually invokable action that makes a release. Parameter `release_version`
  and `next_development_version` are required and will be used for making the release and
  preparing the repo for the next development cycle. This action makes changes to the repo
  (`pom.xml`, `CHANGELOG.md`), which are committed to a new branch, and a PR to `main` is
  created during its execution. This PR has to be merged manually when we are happy with
  the results of the release.

## Changes to sources that were required

- introduce a placeholder, `$$QUDT_VERSION$$` wherever the current version is needed
- move the rdf source folders from the root dir to `src/main/rdf`
   (not technically required, but makes clear what is source and what is generated)
- add CHANGELOG.md

## Other changes

- Folder structure: the `collections` folder ended up as `src/main/validation`

## Documentation

- build phases and associated plugin executions are listed in the comments in `pom.xml`
  • Loading branch information
fkleedorfer committed Nov 11, 2024
1 parent 84400d9 commit d7e5cc4
Show file tree
Hide file tree
Showing 61 changed files with 24,593 additions and 39,676 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
pull_request:
types:
- closed
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -Pzip install
# Make github release
- name: Release
uses: softprops/action-gh-release@v2
if: ${{ github.ref_name == 'main' && github.event.pull_request.merged == true}} # only make snapshot release if it is a push to main
with:
name: Latest snapshot release
tag_name: snapshot
body: Snapshot release triggered by an update of the main branch.
files: target/qudt-public-repo-*.zip
150 changes: 150 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# sets up java, maven and gpg
# sets up settings.xml in such a way that the build/deploy works
# releases the project with specified version
# deploys it to the sonatype staging repo
name: Release
on:
workflow_dispatch:
inputs:
release_version:
description: 'Release version (such as 2.3.13)'
required: true
type: string
next_snapshot_version:
description: 'Next SNAPSHOT version (such as 2.4-SNAPSHOT)'
required: true
type: string

jobs:
build:
# setting the environment on the job is mandatory, otherwise it cannot access environment secrets.
runs-on: ubuntu-latest

steps:
- name: Check write access to repo
run: |
token_login=$(curl -H "Authorization: Bearer ${token}" https://api.github.com/user | jq -r '.login')
echo token login is ${token_login}
echo $(curl -H "Authorization: Bearer ${token}" https://api.github.com/repos/${repo}/collaborators/${token_login}/permission) > result
cat result | jq '.permission == "admin" // .permission == "write"' > /dev/null || ( echo "Token does not have write access to ${repo}" >> ${GITHUB_STEP_SUMMARY}; exit 1)
curl -sS -f -I -H "Authorization: Bearer ${token}" https://api.github.com | grep 'x-oauth-scopes:' | grep 'repo' > /dev/null && exit 0 || echo "Token does not have repo scope on ${repo}" >> ${GITHUB_STEP_SUMMARY}
env:
repo: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}

# check if a tag already exists for the version we want to publish - in that case the workflow
# will fail later, so let us make it fail fast
- name: Check if tag v${{ inputs.release_version }} exists
uses: mukunku/[email protected]
id: checkTag
with:
tag: v${{ inputs.release_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if tag v${{ inputs.release_version }} exists
if: steps.checkTag.outputs.exists == 'true'
run: |
echo Tag v${{ inputs.release_version }} already exists, release aborted >> $GITHUB_STEP_SUMMARY
exit 1
# Set up java with maven cache
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'

# configure git
- name: setup git config
run: |
git config user.name ${{ github.actor }}
git config user.email "<>"
# because we protect the main branch, the action cannot push to the repository
# Therefore, we create a branch for the release, and if the release succeeds, we will
# submit a pull request
# Note: outputs the name of the new branch as ${{ steps.create_release_branch.outputs.branch_name }}
- name: create branch for this release
id: create_release_branch
run: |
BRANCH_NAME=release-$version-$(date +%s)
git checkout --track -b $BRANCH_NAME
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
env:
version: ${{ inputs.release_version }}

# Push to the remote so we create the remote branch without any changes
# because the create-pull-request action (see below) will only include unpushed
# changes in the PR
- name: Push changes to repository
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git push origin

# Update changelog unreleased section with new version
- name: Update changelog
uses: superfaceai/release-changelog-action@v1
with:
path-to-changelog: CHANGELOG.md
version: ${{ inputs.release_version }}
operation: release

# Apply formatting (changelog was touched)
- name: Apply format using spotless:apply
run: mvn spotless:apply -DspotlessFiles='.*CHANGELOG.md'

# Commit changes
- name: Commit CHANGELOG.md
run: |
git add "CHANGELOG.md"
git commit -m "Update CHANGELOG.md for release ${{ inputs.release_version }}"
# build release
- name: Build with Maven, deploying to sonatype staging repo
run: mvn -Pzip -B release:clean release:prepare release:perform -DtagNameFormat="v@{project.version}" -DreleaseVersion=${{ inputs.release_version }} -DdevelopmentVersion=${{ inputs.next_snapshot_version }}

# Make github release
- name: Release
uses: softprops/action-gh-release@v2
with:
files: target/qudt-public-repo-*.zip

# Read version changelog
- id: get-changelog
name: Get version changelog
uses: superfaceai/release-changelog-action@v1
with:
path-to-changelog: CHANGELOG.md
version: ${{ inputs.release_version }}
operation: read

# create the pull request
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: Release ${{ inputs.release_version }}
base: main
branch: ${{ steps.create_release_branch.outputs.branch_name }}
delete-branch: true
body: |
# Changes
${{ steps.get-changelog.outputs.changelog }}
# Release info
Automated release through workflow: '${{ github.workflow }}'
Triggered by: ${{ github.triggering_actor }}
Version: ${{ inputs.release_version }}
Next development version: ${{ inputs.next_snapshot_version }}
# Next Steps
Please rebase this PR on top of `main` after verifying the release is ok.
# print the summary
- name: Print summary
run: echo "Release ${{ inputs.release_version }} deployed to sonatype staging repo. Please go there, close the repo and publish it." >> $GITHUB_STEP_SUMMARY
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# MacOS cruft
.DS_Store
/**/.DS_Store

# Byte-compiled / optimized / DLL python files
__pycache__/
Expand All @@ -13,4 +13,7 @@ __pycache__/
*.diagrams

# JetBrains stuff
.idea/
.idea/

# maven
/target
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project is in the process of adopting [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Added `skos:broader` relations to a number of quantity kinds that had none. Note that it is ok for a
quantity kind to have no broader quantity kind, but these were missing.
- Changed the erroneously used 'qudt:hasDimensionVector' property in `vocab/types/VOCAB_QUDT_DATATYPES-v2.1.ttl`
file with with a new property qudt:dimensions that denotes the dimensions of a matrix.

## [2.1.44] - 2024-10-27

### Fixed

- A new quantity kind, ElevationRelativeToNAP, has been added to support the Amsterdam Ordnance
System (thanks @RiX012).
- **Big housecleaning month!** Many of the unused graphs that have been lying around the repository
have been moved to a behind-the-scenes repository, including references to some of the unused
concepts in our active graphs. If you have been quietly using them yourself in your own work and
would like us to restore any of them, please let us know in a new Issue. Otherwise, we now have a
more streamlined repository while retaining all the functionality you have been depending on.
- The qudt:currencyNumber relation now points to a string with the currency code, rather than an
integer. This makes sense because it is not used for computation - it is a code in the true
sense. (Thanks for this fix, @fkleedorfer)
- A number of units now point to quantitykind:MassConcentration in addition to MassDensity and Density.
(thanks @J-meirlaen). (MassDensity and Density are already declared as qudt:exactMatch.
MassConcentration will be included in these declarations in the future.)

[Unreleased]: https://github.com/qudt/qudt-public-repo/compare/v2.1.43...HEAD
[2.1.44]: https://github.com/qudt/qudt-public-repo/compare/v2.1.43...v2.1.44
4 changes: 2 additions & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Creative Commons Attribution 4.0 International License (CC BY 4.0),
available at https://creativecommons.org/licenses/by/4.0/.
Creative Commons Attribution 4.0 International License (CC BY 4.0),
available at https://creativecommons.org/licenses/by/4.0/.
Attribution should be made to QUDT.org"
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ The QUDT ontology is provided in two forms: OWL and SHACL. By default, the vocab

```
Change this line:
owl:imports <http://qudt.org/2.1/schema/shacl/qudt> ;
owl:imports <http://qudt.org/2.1/schema/shacl/qudt> ;
To:
owl:imports <http://qudt.org/2.1/schema/qudt> ;
owl:imports <http://qudt.org/2.1/schema/qudt> ;
```

If you are using the tools from TopQuadrant, you should also change the comment line at the top of the same file:
Expand All @@ -51,9 +51,9 @@ QUDT SHACL is supported by a set of validation rules that check the integrity an

```
Change this line:
owl:imports <http://qudt.org/2.1/collection/qa/all> ;
owl:imports <http://qudt.org/2.1/collection/qa/all> ;
To:
owl:imports <http://qudt.org/2.1/collection/usertest> ;
owl:imports <http://qudt.org/2.1/collection/usertest> ;
```

If you are using the tools from TopQuadrant, you should also change the comment line at the top of the same file:
Expand All @@ -68,7 +68,7 @@ Currently, the tests in the usertest graph check for references to deprecated in

Protege Users
-----------------------------
The QUDT ontologies (Release 2.1.44) have been tested to load without error in Protege 5.6.4.
The QUDT ontologies (Release $$QUDT_VERSION$$) have been tested to load without error in Protege 5.6.4.

To load QUDT into Protege, choose "Open from URI" from the file menu, and enter http://qudt.org/2.1/vocab/unit

Expand All @@ -79,6 +79,47 @@ Ontology libraries

Please note that various libraries exhibit different behaviors when importing the QUDT ontology, see this [discussion](https://github.com/qudt/qudt-public-repo/issues/842#issuecomment-1879114604).

Building
--------

The project uses [maven](https://maven.apache.org/), interpreting the file `pom.xml` to generate the QUDT release files in
`target/dist` and the release zip in `target/qudt-public-repo-[VERSION].zip`

To start the build use
```bash
mvn clean install
```
(leave 'clean' out if you are not concerned about files from a previous build)

To build the release zip file, run
```bash
mvn -Pzip install
```
(This activates the maven profile called 'zip', which you find in the pom.xml near the end).

If you make changes to the project before building, you can expect these problems:

#### Formatting and formatting problems

If the spotless plugin complains about file formatting, run
```
mvn spotless:apply
mvn install
```

#### SHACL validation and validation failures

If the shacl-maven-plugin complains about a SHACL validation failure, have a look
at `target/validation/validationReport.ttl` to see why validation failed and fix the
respective problems in the TTL files, then run `mvn clean install`.

To run the shacl validation (and any build steps required to do so), run

```bash
mvn test
```
####

Status
------

Expand All @@ -87,7 +128,7 @@ Please see the [New Features and Releases](https://github.com/qudt/qudt-public-r


<hr/>
<p style="font-size=xx-small;"><sup>1</sup> QUDT.org is a 501(c)(3) not-for-profit organization founded to provide semantic specifications for units of measure, quantity kind, dimensions and data types. QUDT is an advocate for the development and implementation of standards to quantify data expressed in RDF and JSON. Our mission is to improve interoperability of data and the specification of information structures through industry standards for Units of Measure, Quantity Kinds, Dimensions and Data Types. <a href="https://github.com/sponsors/qudt">Sponsorships</a> are greatly appreciated!
<p style="font-size:xx-small;"><sup>1</sup> QUDT.org is a 501(c)(3) not-for-profit organization founded to provide semantic specifications for units of measure, quantity kind, dimensions and data types. QUDT is an advocate for the development and implementation of standards to quantify data expressed in RDF and JSON. Our mission is to improve interoperability of data and the specification of information structures through industry standards for Units of Measure, Quantity Kinds, Dimensions and Data Types. <a href="https://github.com/sponsors/qudt">Sponsorships</a> are greatly appreciated!

QUDT.org is a member of the World Wide Web Consortium (W3C)

Expand Down
Loading

0 comments on commit d7e5cc4

Please sign in to comment.