Skip to content

Commit

Permalink
Update github workflows
Browse files Browse the repository at this point in the history
Add workflow that creates snapshots on push

Unify publish workflows and create release automatically
  • Loading branch information
ChristophB committed Aug 5, 2022
1 parent caf9a9d commit 0216993
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 75 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/maven-publish.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .github/workflows/npm-publish.yml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/publish-snapshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Publish snapshots

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
server-id: github
settings-path: ${{ github.workspace }}
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B install --no-transfer-progress --file pom.xml

publish-maven-snapshot:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
server-id: github
settings-path: ${{ github.workspace }}

- name: Get version
run: echo project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV
- name: Append "-SNAPSHOT" to projects version
run: mvn versions:set "-DnewVersion=${{ env.project_version }}-SNAPSHOT"

- name: Publish to GitHub Packages Apache Maven
run: mvn -B --no-transfer-progress deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

publish-npm-snapshot:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
server-id: github
settings-path: ${{ github.workspace }}
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://npm.pkg.github.com

- name: Get version
run: echo project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV
- name: Get short commit hash
run: echo commit=$(git rev-parse --short HEAD) >> $GITHUB_ENV
- name: Append commit hash to projects version
run: mvn versions:set "-DnewVersion=${{ env.project_version }}-${{ env.commit }}"

- name: Build with Maven
run: mvn -B --no-transfer-progress package --file pom.xml

- name: Install dependencies
working-directory: ./target/generated-sources/openapi/axios
run: npm install
- name: Publish npm package
working-directory: ./target/generated-sources/openapi/axios
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This workflow will build a package using Maven and publish it to GitHub Packages. It will also create a new release.

name: Publish packages and create release

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
server-id: github
settings-path: ${{ github.workspace }}
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- run: mvn -B install --no-transfer-progress --file pom.xml

publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
server-id: github
settings-path: ${{ github.workspace }}
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://npm.pkg.github.com
- name: Get version
run: echo project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV

- name: Publish to GitHub Packages Apache Maven
run: mvn -B --no-transfer-progress deploy -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Install dependencies
working-directory: ./target/generated-sources/openapi/axios
run: npm install
- name: Publish npm package
working-directory: ./target/generated-sources/openapi/axios
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Create release
uses: "softprops/action-gh-release@v1"
with:
tag_name: v${{ env.project_version }}
prerelease: false
name: v${{ env.project_version }}
generate_release_notes: true
fail_on_unmatched_files: true
body: |
Maven:
```
<dependencies>
<dependency>
<groupId>care.smith.top</groupId>
<artifactId>top-api</artifactId>
<version>${{ env.project_version }}</version>
</dependency>
</dependencies>
```
files: |
LICENSE
target/*.jar
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

This repository contains the OpenAPI 3 specification of the TOP framework. The schema file is located at [schemas/top-api.yaml](schemas/top-api.yaml)

[![Node.js Package](https://github.com/Onto-Med/top-api/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/Onto-Med/top-api/actions/workflows/npm-publish.yml)
[![Maven Package](https://github.com/Onto-Med/top-api/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/Onto-Med/top-api/actions/workflows/maven-publish.yml)
[![Publish snapshots](https://github.com/Onto-Med/top-api/actions/workflows/publish-snapshots.yml/badge.svg)](https://github.com/Onto-Med/top-api/actions/workflows/publish-snapshots.yml)
[![Publish packages and create release](https://github.com/Onto-Med/top-api/actions/workflows/release.yml/badge.svg)](https://github.com/Onto-Med/top-api/actions/workflows/release.yml)

## Development

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>care.smith.top</groupId>
<artifactId>top-api</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.4.1</version>

<name>TOP API</name>
<description>REST API of the TOP framework</description>
Expand Down

0 comments on commit 0216993

Please sign in to comment.