Skip to content

Commit a8832d2

Browse files
committed
Adding action to build for Samples
1 parent 68be6cd commit a8832d2

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

.github/workflows/samples.yaml

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

0 commit comments

Comments
 (0)