Skip to content

Commit

Permalink
Refactored dev-build and release workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximilianWenzel committed Apr 11, 2024
1 parent a948ea2 commit 8e23806
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 130 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ on:
- master

jobs:
build-and-upload:
uses: ./.github/workflows/java-build.yml
with:
java-version: 17
dev-build:
name: "Build Artifacts"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: ./.github/workflows/mvn-setup

- name: Build with Maven
run: mvn --no-transfer-progress -B package --file pom.xml -Dchangelist=${CHANGELIST}

- name: Get artifact path
if: ${{ github.actor != 'dependabot[bot]' }}
run: |
echo "build_name=neo2rdf-build_${{ env.NORMALIZED_BRANCH_NAME }}" >> $GITHUB_ENV
echo "build_path=$(ls target/*.zip | head -n 1)" >> $GITHUB_ENV
- name: Upload RDF build
uses: actions/upload-artifact@v4
if: ${{ github.actor != 'dependabot[bot]' }}
with:
name: ${{ env.build_name }}
path: ${{ env.build_path }}
36 changes: 0 additions & 36 deletions .github/workflows/java-build.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/mvn-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Setup Environment"
description: "Sets up the environment to build the Java project with maven"
runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: maven

- name: Extract branch or tag name
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "VERSION=$VERSION" >> $GITHUB_ENV
else
NORMALIZED_BRANCH_NAME=$(echo "${GITHUB_REF#refs/heads/}" | tr '/' '-')
echo "NORMALIZED_BRANCH_NAME=$NORMALIZED_BRANCH_NAME" >> $GITHUB_ENV
fi
shell: bash

- name: Determine changelist
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
CHANGELIST=''
else
CHANGELIST=$(test "${GITHUB_REF#refs/heads/}" == 'master' && echo '' || echo "-$NORMALIZED_BRANCH_NAME-SNAPSHOT")
fi
echo "CHANGELIST=$CHANGELIST" >> $GITHUB_ENV
shell: bash


48 changes: 16 additions & 32 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,24 @@ on:
- 'v*'

jobs:
build-job:
uses: ./.github/workflows/java-build.yml
with:
java-version: 17
maven-options: "-P release"
release-job:
needs: build-job
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: maven-build
path: release-artifacts/
- name: Get path name of artifact
run: echo "ARTIFACT_PATHNAME=$(ls release-artifacts/*.zip | head -n 1)" >> $GITHUB_ENV
- name: Get basename of artifact path
run: echo "ARTIFACT_NAME=$(basename ${{ env.ARTIFACT_PATHNAME }})" >> $GITHUB_ENV
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4

- uses: ./.github/workflows/mvn-setup

- name: Build with Maven
run: mvn --no-transfer-progress -B package --file pom.xml -Dchangelist=${CHANGELIST}

- name: Get artifact path
run: |
echo "build_name=neo2rdf-build_${{ env.NORMALIZED_BRANCH_NAME }}" >> $GITHUB_ENV
echo "build_path=$(ls target/*.zip | head -n 1)" >> $GITHUB_ENV
- name: Create release
uses: softprops/action-gh-release@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_PATHNAME }}
asset_name: ${{ env.ARTIFACT_NAME }}
asset_content_type: application/zip
files: |
${{ env.build_path }}
60 changes: 2 additions & 58 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@
<artifactId>neo2rdf</artifactId>
<version>${revision}</version>

<profiles>
<profile>
<id>release</id>
<properties>
<revision>${version}</revision>
</properties>
</profile>
</profiles>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<!--suppress UnresolvedMavenProperty -->
<sha1>${git.branch}</sha1>
<version>1.0.0</version>
<sha1/>
<changelist/>
<revision>${version}-${sha1}${changelist}-SNAPSHOT</revision>
<revision>1.0.0${sha1}${changelist}</revision>
<version.mvn.plugin.flatten>1.1.0</version.mvn.plugin.flatten>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<neo4j.version>5.18.1</neo4j.version>
Expand Down Expand Up @@ -67,51 +56,6 @@
<artifactId>license-maven-plugin</artifactId>
<version>2.4.0</version>
</plugin>
<!-- https://mvnrepository.com/artifact/io.github.git-commit-id/git-commit-id-maven-plugin -->
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>7.0.0</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.directory}/git.properties
</generateGitPropertiesFilename>
<injectAllReactorProjects>true</injectAllReactorProjects>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>^git.branch</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
<replacementProperties>
<replacementProperty>
<property>git.branch</property>
<token>^([^\/]*)\/([^\/]*)$</token>
<value>$1-$2</value>
<regex>true</regex>
<transformationRules>
<transformationRule>
<apply>BEFORE</apply>
<action>UPPER_CASE</action>
</transformationRule>
<transformationRule>
<apply>AFTER</apply>
<action>LOWER_CASE</action>
</transformationRule>
</transformationRules>
</replacementProperty>
</replacementProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down

0 comments on commit 8e23806

Please sign in to comment.