Skip to content

Commit

Permalink
Add github actions and spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
kloessst committed Oct 19, 2020
1 parent 3ad0525 commit 85aa31d
Show file tree
Hide file tree
Showing 3 changed files with 458 additions and 0 deletions.
103 changes: 103 additions & 0 deletions .github/actions/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Continous Integration

on:
pull_request:
push:
branches:
- master
tags: 'v[0-9]+.[0-9]+.[0-9]+'
paths-ignore:
- './idea'
- 'README.md'
- 'LICENSE'
- '.github/**'
- '!.github/workflows/**'

env:
java: 1.8

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '${{ env.java }}'
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Spotless
run: mvn -B spotless:check
- name: Build
run: mvn package -B -DskipTests=true
- name: Copy artifact
run: mkdir staging && cp target/*.jar staging
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: plugin
path: staging

release:
needs: [build, test]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Get tag
id: get_version
run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: false
- name: Download pre-build artifact
uses: actions/download-artifact@v2
with:
name: plugin
path: staging
- name: Get artifact name
id: get_artifact_name
run: |
cd staging
echo ::set-output name=ARTIFACT::$(ls *.jar)
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: staging/${{ steps.get_artifact_name.outputs.ARTIFACT }}
asset_name: ${{ steps.get_artifact_name.outputs.ARTIFACT }}
asset_content_type: application/zip

test:
runs-on: ubuntu-latest
steps:
- name: Setup Java
uses: actions/setup-java@v1
with:
java-version: '${{ env.java }}'
- uses: actions/checkout@v2
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Tests
run: mvn -B test
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.version>2.176.1</jenkins.version>
<java.level>8</java.level>
<spotless.version>2.4.2</spotless.version>
<!-- Other properties you may want to use:
~ jenkins-test-harness.version: Jenkins Test Harness version you use to test the plugin. For Jenkins version >= 1.580.1 use JTH 2.0 or higher.
~ hpi-plugin.version: The HPI Maven Plugin version used by the plugin..
Expand Down Expand Up @@ -105,6 +106,33 @@
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
</scm>
-->
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<!-- limit format enforcement to just the files changed by this feature branch -->
<ratchetFrom>origin/master</ratchetFrom>
<!-- define a language-specific format -->
<java>
<!-- These are the defaults, you can override if you want -->
<includes>
<include>src/main/java/**/*.java</include>
</includes>
<importOrder> <!-- or a custom ordering -->
<order>java,javax,org,com,de</order>
</importOrder>
<removeUnusedImports/>
<eclipse>
<file>${basedir}/spotless-style.xml</file> <!-- optional -->
</eclipse>
</java>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand Down
Loading

0 comments on commit 85aa31d

Please sign in to comment.