-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcontinuous-integration-workflow.yml
More file actions
112 lines (101 loc) · 4.13 KB
/
continuous-integration-workflow.yml
File metadata and controls
112 lines (101 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Botz CI
env:
CI: true
on: [push, pull_request]
jobs:
build:
name: Build Botz from source
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 17 ]
steps:
- uses: actions/checkout@v5
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Cache Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-java${{ matrix.java }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-java${{ matrix.java }}-maven-
${{ runner.os }}-
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Upload distribution
uses: actions/upload-artifact@v4
with:
name: distribution-java${{ matrix.java }}
path: target/botz-*.jar
check_branch:
runs-on: ubuntu-latest
outputs:
is_publishable_branch: ${{ steps.check-branch.outputs.is_publishable_branch }}
steps:
- name: check branch ${{ github.ref }} is either main or a version number
id: check-branch
run: |
if [[ ${{ github.ref }} == 'refs/heads/main' || ${{ github.ref }} =~ refs\/heads\/[0-9]+\.[0-9]+ ]]; then
echo "is_publishable_branch=true" >> $GITHUB_OUTPUT
else
echo "is_publishable_branch=false" >> $GITHUB_OUTPUT
fi
publish-maven:
name: Publish to Maven
runs-on: ubuntu-latest
needs: [build, check_branch]
if: ${{github.repository == 'igniterealtime/Botz' && github.event_name == 'push' && ( needs.check_branch.outputs.is_publishable_branch == 'true' || contains(github.ref, 'refs/tags/') ) }}
steps:
- uses: actions/checkout@v5
with:
# Defend against another commit quickly following the first
# We want the one that's been tested, rather than the head of main
ref: ${{ github.event.push.after }}
- id: get-id
name: Compute needed variables
run: |
set -x
tag=$(echo ${{ github.ref }} | cut -d '/' -f3)
echo "tag=$tag" >> $GITHUB_OUTPUT
echo "tag is '$tag'"
version=$(echo ${{ github.ref }} | cut -d '/' -f3 | cut -c 2-)
echo "version=$version" >> $GITHUB_OUTPUT
echo "version is '$version'"
rel_id=$(curl -sL --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' https://api.github.com/repos/${{github.repository}}/releases | jq -r --arg TAG "$tag" '.[] | select(.tag_name==$TAG) | .id')
echo "rel_id=$rel_id" >> $GITHUB_OUTPUT
echo "rel_id is '$rel_id'"
- name: Cache Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-java11-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-java11-maven-
${{ runner.os }}-
- name: Set up Java for publishing
uses: actions/setup-java@v5
with:
java-version: 11
distribution: temurin
server-id: igniterealtime
server-username: IGNITE_REALTIME_MAVEN_USERNAME
server-password: IGNITE_REALTIME_MAVEN_PASSWORD
- name: Publish
run: mvn -B -Dmaven.resolver.transport=wagon deploy
env:
IGNITE_REALTIME_MAVEN_USERNAME: ${{ secrets.IGNITE_REALTIME_MAVEN_USERNAME }}
IGNITE_REALTIME_MAVEN_PASSWORD: ${{ secrets.IGNITE_REALTIME_MAVEN_PASSWORD }}
- name: Push Artifact to Github Release
uses: actions/upload-release-asset@v1
if: ${{ contains(github.ref, 'refs/tags/') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: https://uploads.github.com/repos/${{ github.repository }}/releases/${{ steps.get-id.outputs.rel_id }}/assets?name=botz-${{ steps.get-id.outputs.version }}.jar
asset_path: target/botz-${{ steps.get-id.outputs.version }}.jar
asset_name: botz-${{ steps.get-id.outputs.version }}.jar
asset_content_type: application/java-archive