-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (126 loc) · 5.01 KB
/
build.yml
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com) and contributors
# SPDX-FileContributor: Sebastian Thomschke (https://sebthom.de), Vegard IT GmbH (https://vegardit.com)
# SPDX-License-Identifier: EPL-2.0
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/no-npe
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Build
on:
push:
branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
tags-ignore: # don't build tags
- '**'
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '.github/*.yml'
pull_request:
workflow_dispatch:
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
inputs:
additional_maven_args:
description: 'Additional Maven Args'
required: false
default: ''
defaults:
run:
shell: bash
jobs:
build:
runs-on: ubuntu-latest
concurrency: ci-${{ github.ref }}
steps:
- name: Git Checkout
uses: actions/checkout@v4 # https://github.com/actions/checkout
- name: Set up JDK 11
uses: actions/setup-java@v3 # https://github.com/actions/setup-java
with:
distribution: temurin
java-version: 11
- run: echo "JAVA11_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v3 # https://github.com/actions/setup-java
with:
distribution: temurin
java-version: 17
- run: echo "JAVA17_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: "Cache: Local Maven Repository"
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/**/*SNAPSHOT*
key: ${{ runner.os }}-mvnrepo-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-mvnrepo-
- name: Set up Maven
uses: stCarolas/[email protected]
with:
maven-version: 3.9.3
- name: Test with Maven
id: maven-test
if: ${{ github.ref != 'refs/heads/main' }}
run: |
bash .ci/build.sh ${{ github.event.inputs.additional_maven_args }}
- name: Prepare Maven Snapshots Repo
if: github.ref == 'refs/heads/main'
run: |
set -eux
cd /tmp
github_repo_url="https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}/"
if curl --output /dev/null --silent --head --fail "$github_repo_url/tree/mvn-snapshots-repo"; then
git clone https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}/ --single-branch --branch mvn-snapshots-repo mvn-snapshots-repo
cd mvn-snapshots-repo
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git reset --hard HEAD^ # revert previous commit
else
git clone https://${{ github.actor }}:${{ github.token }}@github.com/${{ github.repository }}/ mvn-snapshots-repo
cd mvn-snapshots-repo
git checkout --orphan mvn-snapshots-repo
git rm -rf .
cat <<EOF > index.html
<!DOCTYPE html>
<html>
<head>
<title>${{ github.repository }} - Maven Snapshots Repo</title>
</head>
<body>
<h1>${{ github.repository }} - Maven Snapshots Repo</h1>
</body>
</html>
EOF
git add index.html
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "Initialize Maven Snapshots Repo"
fi
- name: Build with Maven
id: maven-build
if: ${{ github.ref == 'refs/heads/main' }}
env:
MAY_CREATE_RELEASE: true
SIGN_KEY: ${{ secrets.GPG_SIGN_KEY }}
SIGN_KEY_PASS: ${{ secrets.GPG_SIGN_KEY_PWD }}
SONATYPE_OSSRH_USER: ${{ secrets.SONATYPE_OSSRH_USER }}
SONATYPE_OSSRH_USER_TOKEN: ${{ secrets.SONATYPE_OSSRH_USER_TOKEN }}
run: |
set -eu
# https://github.community/t/github-actions-bot-email-address/17204
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bash .ci/build.sh \
${{ github.event.inputs.additional_maven_args }} \
-DaltSnapshotDeploymentRepository=temp-snapshots-repo::default::file:///tmp/mvn-snapshots-repo
- name: Update Maven Snapshots Repo
if: github.ref == 'refs/heads/main'
run: |
cd /tmp/mvn-snapshots-repo
if [[ $(git -C . ls-files -o -m -d --exclude-standard | wc -l) -gt 0 ]]; then
git add --all
git commit -am "Deploy snapshot version"
git push origin mvn-snapshots-repo --force
fi