Skip to content

Commit

Permalink
fix: upload tests jar to maven central and github packages (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriev authored Aug 9, 2024
1 parent 04d93d6 commit 89dd429
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
47 changes: 25 additions & 22 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
name: maven-build
on:
push:
branches: ['**/**']
branches: [main]

This comment has been minimized.

Copy link
@ariwk

ariwk Aug 10, 2024

Collaborator

why only on main? we have already changed that from main to / --> IMHO is better

pull_request:

This comment has been minimized.

Copy link
@ariwk

ariwk Aug 10, 2024

Collaborator

we had that and we removed it because it was not covering everying

types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -15,23 +17,25 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
MARKDOWN2HTML_MAVEN_PLUGIN_FAIL_ON_ERROR: true
steps:
- name: Checkout
- name: 📄 Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- name: Set up JDK and Maven
with:
fetch-depth: 0
- name: 🧱 Set up JDK and Maven
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4
with:
distribution: adopt
java-version: 17
gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }}
- name: Prepare Cache
- name: 💾 Prepare Cache
id: prepare-cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: |
/home/runner/.m2
/home/runner/work
key: ${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}
- name: Generate settings.xml
- name: 🔘 Generate settings.xml
uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22
with:
repositories: >
Expand Down Expand Up @@ -78,14 +82,14 @@ jobs:
}
}
]
- name: Print settings.xml
- name: 🔘 Print settings.xml
run: cat /home/runner/.m2/settings.xml
- name: Build with Maven
- name: 📦 Build with Maven
run: mvn --batch-mode clean package
- name: Store project version
- name: 📝 Store project version
id: project_version
run: echo "project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT
- name: Store cache key
- name: 📝 Store cache key
id: cache_key
run: echo "cache_key=${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}" >> $GITHUB_OUTPUT
outputs:
Expand All @@ -104,22 +108,22 @@ jobs:
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN }}
COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE }}
steps:
- name: Set up JDK and Maven
- name: 🧱 Set up JDK and Maven
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4
with:
distribution: adopt
java-version: 17
gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }}
- name: Restore Cache
- name: 💾 Restore Cache
id: restore-cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: |
/home/runner/.m2
/home/runner/work
key: ${{ needs.build.outputs.cache_key }}
- name: Publish to Maven Central
run: mvn --batch-mode -Dmaven.test.skip=true deploy -P gpg-sign -P nexus-staging
- name: 📦 Publish to Maven Central
run: mvn --batch-mode deploy -P gpg-sign -P nexus-staging

# deploy to GitHub Packages
deploy-github-packages:
Expand All @@ -134,22 +138,21 @@ jobs:
S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY: ${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY }}
GITHUB_TOKEN: ${{ github.token }}
steps:
- name: Set up JDK and Maven
- name: 🧱 Set up JDK and Maven
uses: actions/setup-java@6a0805fcefea3d4657a47ac4c165951e33482018 # v4
with:
distribution: adopt
java-version: 17
- name: Cache
id: cache
- name: 💾 Restore Cache
id: restore-cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: |
/home/runner/.m2
/home/runner/work
key: ${{ needs.build.outputs.cache_key }}
- name: Publish to GitHub Packages
run: mvn --batch-mode -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true deploy -P deploy-github-packages
- name: Upload assets
run: cd ${{github.workspace}} && gh release upload v${{ needs.build.outputs.project_version }} **/target/*-${{ needs.build.outputs.project_version }}.jar && gh release upload
v${{ needs.build.outputs.project_version }} **/target/*-${{ needs.build.outputs.project_version }}-tests.jar
shell: bash
- name: 📦 Publish to GitHub Packages
run: mvn --batch-mode -Dmaven.javadoc.skip=true -Dmaven.source.skip=true deploy -P deploy-github-packages
- name: 📦 Upload assets
run: gh release upload v${{ needs.build.outputs.project_version }} **/target/*-${{ needs.build.outputs.project_version }}.jar && gh release upload v${{ needs.build.outputs.project_version }}
**/target/*-${{ needs.build.outputs.project_version }}-tests.jar
16 changes: 14 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<maven-dependency-plugin.version>3.7.1</maven-dependency-plugin.version>
<exec-maven-plugin.version>3.3.0</exec-maven-plugin.version>
<swagger-maven-plugin.version>2.2.22</swagger-maven-plugin.version>
<sonar-maven-plugin.version>4.0.0.4121</sonar-maven-plugin.version>

<!-- Test dependencies -->
<junit.version>5.10.3</junit.version>
Expand Down Expand Up @@ -649,21 +650,32 @@
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<id>report</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar-maven-plugin.version}</version>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand Down

0 comments on commit 89dd429

Please sign in to comment.