Skip to content

Commit bf9f7b8

Browse files
authored
Create maven.yml
1 parent 34142fe commit bf9f7b8

1 file changed

Lines changed: 148 additions & 0 deletions

File tree

.github/workflows/maven.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# The following workflow provides an opinionated template you can customize for your own needs.
2+
#
3+
# To configure Octopus, set the OCTOPUS_API_TOKEN secret to the Octopus API key, and
4+
# set the OCTOPUS_SERVER_URL secret to the Octopus URL.
5+
#
6+
# Double check the "project" and "deploy_to" properties in the "Create Octopus Release" step
7+
# match your Octopus projects and environments.
8+
#
9+
# Get a trial Octopus instance from https://octopus.com/start
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v1
16+
with:
17+
fetch-depth: '0'
18+
- name: Install GitVersion
19+
uses: gittools/actions/gitversion/setup@v0.9.7
20+
with:
21+
versionSpec: 5.x
22+
- id: determine_version
23+
name: Determine Version
24+
uses: gittools/actions/gitversion/execute@v0.9.7
25+
with:
26+
additionalArguments: /overrideconfig mode=Mainline
27+
- name: Install Octopus Deploy CLI
28+
uses: OctopusDeploy/install-octocli@v1.1.1
29+
with:
30+
version: latest
31+
- name: Set up JDK 1.17
32+
uses: actions/setup-java@v2
33+
with:
34+
java-version: '17'
35+
distribution: adopt
36+
- name: Set Version
37+
run: ./mvnw --batch-mode versions:set -DnewVersion=${{ steps.determine_version.outputs.semVer }}
38+
shell: bash
39+
- name: List Dependencies
40+
run: ./mvnw --batch-mode dependency:tree --no-transfer-progress > dependencies.txt
41+
shell: bash
42+
- name: Collect Dependencies
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: Dependencies
46+
path: dependencies.txt
47+
- name: List Dependency Updates
48+
run: ./mvnw --batch-mode versions:display-dependency-updates > dependencyUpdates.txt
49+
shell: bash
50+
- name: Collect Dependency Updates
51+
uses: actions/upload-artifact@v2
52+
with:
53+
name: Dependencies Updates
54+
path: dependencyUpdates.txt
55+
- name: Test
56+
run: ./mvnw --batch-mode -Dmaven.test.failure.ignore=true test
57+
shell: bash
58+
- if: always()
59+
name: Report
60+
uses: dorny/test-reporter@v1
61+
with:
62+
name: Maven Tests
63+
path: target/surefire-reports/*.xml
64+
reporter: java-junit
65+
fail-on-error: 'false'
66+
- name: Package
67+
run: ./mvnw --batch-mode -DskipTests=true package
68+
shell: bash
69+
- id: get_artifact
70+
name: Get Artifact Path
71+
run: |-
72+
# Find the largest WAR or JAR, and assume that was what we intended to build.
73+
echo "::set-output name=artifact::$(find target -type f \( -iname \*.jar -o -iname \*.war \) -printf "%p\n" | sort -n | head -1)"
74+
shell: bash
75+
- id: get_artifact_name
76+
name: Get Artifact Name
77+
run: |-
78+
# Get the filename without a path
79+
path="${{ steps.get_artifact.outputs.artifact }}"
80+
echo "::set-output name=artifact::${path##*/}"
81+
shell: bash
82+
- name: Tag Release
83+
uses: mathieudutour/github-tag-action@v6.0
84+
with:
85+
custom_tag: ${{ steps.determine_version.outputs.semVer }}
86+
github_token: ${{ secrets.GITHUB_TOKEN }}
87+
- env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
id: create_release
90+
name: Create Release
91+
uses: actions/create-release@v1
92+
with:
93+
tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }}
94+
release_name: Release ${{ steps.determine_version.outputs.semVer }} Run ${{ github.run_number }} Attempt ${{ github.run_attempt }}
95+
draft: 'false'
96+
prerelease: 'false'
97+
- env:
98+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
name: Upload Release Asset
100+
uses: actions/upload-release-asset@v1
101+
with:
102+
upload_url: ${{ steps.create_release.outputs.upload_url }}
103+
asset_path: ${{ steps.get_artifact.outputs.artifact }}
104+
asset_name: ${{ steps.get_artifact_name.outputs.artifact }}
105+
asset_content_type: application/octet-stream
106+
- id: get_octopus_artifact
107+
name: Create Octopus Artifact
108+
run: |-
109+
# Octopus expects artifacts to have a specific file format
110+
file="${{ steps.get_artifact.outputs.artifact }}"
111+
extension="${file##*.}"
112+
octofile="maven1application.${{ steps.determine_version.outputs.semVer }}.${extension}"
113+
cp ${file} ${octofile}
114+
echo "::set-output name=artifact::${octofile}"
115+
# The version used when creating a release is the package id, colon, and version
116+
octoversion="maven1application:${{ steps.determine_version.outputs.semVer }}"
117+
echo "::set-output name=octoversion::${octoversion}"
118+
ls -la
119+
shell: bash
120+
- name: Push to Octopus
121+
uses: OctopusDeploy/push-package-action@v1.1.1
122+
with:
123+
api_key: ${{ secrets.OCTOPUS_API_TOKEN }}
124+
packages: ${{ steps.get_octopus_artifact.outputs.artifact }}
125+
server: ${{ secrets.OCTOPUS_SERVER_URL }}
126+
overwrite_mode: OverwriteExisting
127+
- name: Generate Octopus Deploy build information
128+
uses: xo-energy/action-octopus-build-information@v1.1.2
129+
with:
130+
octopus_api_key: ${{ secrets.OCTOPUS_API_TOKEN }}
131+
octopus_project: maven1application
132+
octopus_server: ${{ secrets.OCTOPUS_SERVER_URL }}
133+
push_version: ${{ steps.determine_version.outputs.semVer }}
134+
push_package_ids: maven1application
135+
push_overwrite_mode: OverwriteExisting
136+
output_path: octopus
137+
- name: Create Octopus Release
138+
uses: OctopusDeploy/create-release-action@v1.1.1
139+
with:
140+
api_key: ${{ secrets.OCTOPUS_API_TOKEN }}
141+
project: maven1application
142+
server: ${{ secrets.OCTOPUS_SERVER_URL }}
143+
deploy_to: Development
144+
packages: ${{ steps.get_octopus_artifact.outputs.octoversion }}
145+
name: Java Maven Build
146+
'on':
147+
workflow_dispatch: {}
148+
push: {}

0 commit comments

Comments
 (0)