-
Notifications
You must be signed in to change notification settings - Fork 1
81 lines (79 loc) · 3.03 KB
/
ci.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
name: ci
on:
push:
branches:
- "**"
defaults:
run:
shell: bash
jobs:
get-runner-user:
runs-on: ubuntu-20.04
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "uid_gid=$(id -u):$(id -g)" >> "$GITHUB_OUTPUT"
build-and-deploy:
needs: get-runner-user
runs-on: ubuntu-20.04
container:
image: "public.ecr.aws/docker/library/maven:3-eclipse-temurin-17"
options: --user ${{ needs.get-runner-user.outputs.uid_gid }}
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
- name: store branch name in environment
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF##*/})" >> "$GITHUB_ENV"
- name: git config
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: configure maven
run: |
mkdir -p "$HOME/.m2"
cat <<EOF > "$HOME/.m2/settings.xml"
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>\${env.GITHUB_ACTOR}</username>
<password>\${env.GITHUB_TOKEN}</password>
</server>
</servers>
</settings>
EOF
- name: conditional release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export MAVEN_OPTS="-Duser.home=$HOME" # Home directory not automatically picked up for some reason
major_version="$(sed -n "s/^.*<major-version>\([0-9]\{1,\}\)<\/major-version>.*$/\1/p" pom.xml)"
date="$(date -u "+%Y%m%d.%H%M%S")"
tag="$major_version.$date"
printf "Tag to use for potential release: %s\n" "$tag"
mvn -B org.apache.maven.plugins:maven-enforcer-plugin:3.0.0-M3:enforce -Drules=requireReleaseDeps
release="false"
git fetch --tags
if [ "$BRANCH_NAME" = "master" ]; then
latest_tag="$(git describe --abbrev=0 || true)"
latest_tag_commit="$(if test -n "$latest_tag"; then git rev-parse "$latest_tag^{}"; fi)"
if [ ! "$latest_tag_commit" = "$GITHUB_SHA" ]; then
release="true"
fi
fi
if [ "$release" = "true" ]; then
# Release to GitHub Packages
mvn -B source:jar deploy scm:tag -DaltReleaseDeploymentRepository="github::default::https://maven.pkg.github.com/capralifecycle/liflig-document-store" -Drevision="$tag" -Dtag="$tag"
else
mvn -B source:jar verify -Drevision="$tag" -Dtag="$tag"
fi