Updating name of Action to differentiate #273
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For a detailed breakdown of this workflow, see https://octopus.com/docs/guides/deploy-java-app/to-tomcat/using-octopus-onprem-github-builtin | |
# | |
# The following workflow provides an opinionated template you can customize for your own needs. | |
# | |
# If you are not an Octopus user, the "Push to Octopus", "Generate Octopus Deploy build information", | |
# and "Create Octopus Release" steps can be safely deleted. | |
# | |
# To configure Octopus, set the OCTOPUS_API_TOKEN secret to the Octopus API key, and | |
# set the OCTOPUS_SERVER_URL secret to the Octopus URL. | |
# | |
# Double check the "project" and "deploy_to" properties in the "Create Octopus Release" step | |
# match your Octopus projects and environments. | |
# | |
# Get a trial Octopus instance from https://octopus.com/start | |
name: Java Maven Build | |
'on': | |
workflow_dispatch: {} | |
push: {} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/setup@v0.9.15 | |
with: | |
versionSpec: 5.x | |
- id: determine_version | |
name: Determine Version | |
uses: gittools/actions/gitversion/execute@v0.9.15 | |
with: | |
additionalArguments: /overrideconfig mode=Mainline | |
- name: Install Octopus Deploy CLI | |
uses: OctopusDeploy/install-octopus-cli-action@v1 | |
with: | |
version: latest | |
- name: Set up JDK 1.17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: adopt | |
- name: Set Version | |
run: ./mvnw --batch-mode versions:set -DnewVersion=${{ steps.determine_version.outputs.semVer }} | |
shell: bash | |
- name: List Dependencies | |
run: ./mvnw --batch-mode dependency:tree --no-transfer-progress > dependencies.txt | |
shell: bash | |
- name: Collect Dependencies | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Dependencies | |
path: dependencies.txt | |
- name: List Dependency Updates | |
run: ./mvnw --batch-mode versions:display-dependency-updates > dependencyUpdates.txt | |
shell: bash | |
- name: Collect Dependency Updates | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Dependencies Updates | |
path: dependencyUpdates.txt | |
- name: Test | |
run: ./mvnw --batch-mode test | |
shell: bash | |
- if: always() | |
name: Report | |
uses: dorny/test-reporter@v1 | |
with: | |
name: Maven Tests | |
path: target/surefire-reports/*.xml | |
reporter: java-junit | |
fail-on-error: 'false' | |
- name: Package | |
run: ./mvnw --batch-mode -DskipTests=true package | |
shell: bash | |
- id: get_artifact | |
name: Get Artifact Path | |
run: |- | |
# Find the largest WAR or JAR, and assume that was what we intended to build. | |
echo "::set-output name=artifact::$(find target -type f \( -iname \*.jar -o -iname \*.war \) -printf "%p\n" | sort -n | head -1)" | |
shell: bash | |
- id: get_artifact_name | |
name: Get Artifact Name | |
run: |- | |
# Get the filename without a path | |
path="${{ steps.get_artifact.outputs.artifact }}" | |
echo "::set-output name=artifact::${path##*/}" | |
shell: bash | |
- name: Tag Release | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
custom_tag: ${{ steps.determine_version.outputs.semVer }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- id: create_release | |
name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }} | |
release_name: Release ${{ steps.determine_version.outputs.semVer }} Run ${{ github.run_number }} Attempt ${{ github.run_attempt }} | |
draft: ${{ github.ref == 'refs/heads/master' && 'false' || 'true' }} | |
name: ${{ github.ref == 'refs/heads/master' && 'false' || 'true' }} | |
- name: Upload Release Asset | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }} | |
files: ${{ steps.get_artifact.outputs.artifact }} | |
- id: get_octopus_artifact | |
name: Create Octopus Artifact | |
run: |- | |
# Octopus expects artifacts to have a specific file format | |
file="${{ steps.get_artifact.outputs.artifact }}" | |
extension="${file##*.}" | |
octofile="RandomQuotes-Java.${{ steps.determine_version.outputs.semVer }}.${extension}" | |
cp ${file} ${octofile} | |
echo "::set-output name=artifact::${octofile}" | |
# The version used when creating a release is the package id, colon, and version | |
octoversion="RandomQuotes-Java:${{ steps.determine_version.outputs.semVer }}" | |
echo "::set-output name=octoversion::${octoversion}" | |
ls -la | |
shell: bash | |
- name: Push packages to Octopus Deploy | |
uses: OctopusDeploy/push-package-action@v3 | |
env: | |
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_TOKEN }} | |
OCTOPUS_URL: ${{ secrets.OCTOPUS_SERVER_URL }} | |
OCTOPUS_SPACE: ${{ secrets.OCTOPUS_SPACE }} | |
with: | |
packages: ${{ steps.get_octopus_artifact.outputs.artifact }} | |
overwrite_mode: OverwriteExisting | |
- name: Generate Octopus Deploy build information | |
uses: OctopusDeploy/push-build-information-action@v3 | |
env: | |
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_TOKEN }} | |
OCTOPUS_URL: ${{ secrets.OCTOPUS_SERVER_URL }} | |
OCTOPUS_SPACE: ${{ secrets.OCTOPUS_SPACE }} | |
with: | |
version: ${{ steps.determine_version.outputs.semVer }} | |
packages: RandomQuotes-Java | |
overwrite_mode: OverwriteExisting | |
- name: Create Octopus Release | |
uses: OctopusDeploy/create-release-action@v3 | |
env: | |
OCTOPUS_API_KEY: ${{ secrets.OCTOPUS_API_TOKEN }} | |
OCTOPUS_URL: ${{ secrets.OCTOPUS_SERVER_URL }} | |
OCTOPUS_SPACE: ${{ secrets.OCTOPUS_SPACE }} | |
with: | |
project: RandomQuotes-Java | |
packages: ${{ steps.get_octopus_artifact.outputs.octoversion }} | |
permissions: | |
id-token: write | |
checks: write | |
contents: write |