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