-
Notifications
You must be signed in to change notification settings - Fork 8
103 lines (87 loc) · 4.43 KB
/
Copy pathformalities.yml
File metadata and controls
103 lines (87 loc) · 4.43 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
name: Codestyle etc.
on: [ pull_request ]
permissions:
contents: read
jobs:
check-formatting:
runs-on: ubuntu-latest
name: Check style
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Java 11
uses: actions/setup-java@v4
with:
distribution: adopt
java-package: jdk
java-version: 17
cache: maven
# Checks that the code sticks to a common code style
- name: Run spotless checks
run: mvn spotless:check || echo "Check the formatting. Use mvn spotless:apply to format the code."
# Runs Maven's dependency analysis to identify unused and undeclared dependencies and fails the build if there are any warnings.
- name: Run dependency analysis
run: mvn dependency:analyze -DfailOnWarning
- name: Get Proposed Version
run: |
echo "PROPOSED_VERSION=$(mvn help:evaluate -Dexpression=project.version -DforceStdout 2>/dev/null | grep -v '^\[' | tail -1)" >> $GITHUB_ENV
- name: Check Semantic Versioning Pattern
run: |
echo "${{ env.PROPOSED_VERSION }}" | \
grep -P '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9A-Za-z-][0-9A-Za-z-]*))*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$'
- name: Enforce -SNAPSHOT version suffix except on release branches
# i.e. release/prep-* branches are allowed to not have -SNAPSHOT.
# Also blocks merging any other PR into develop while develop itself still
# carries the just-released, non-SNAPSHOT version - i.e. before the
# release-publish workflow's auto-merged chore/next-snapshot-* PR has landed.
run: |
if echo "${{ env.PROPOSED_VERSION }}" | grep -q -- "-SNAPSHOT$"; then
HAS_SNAPSHOT_SUFFIX=true
else
HAS_SNAPSHOT_SUFFIX=false
fi
if [[ "${{ github.head_ref }}" == release/prep-* ]]; then
if [ "$HAS_SNAPSHOT_SUFFIX" == "true" ]; then
echo "Release branches (release/prep-*) must not carry a -SNAPSHOT version."
exit 1
fi
else
if [ "$HAS_SNAPSHOT_SUFFIX" == "false" ]; then
echo "Non-release branches must keep a -SNAPSHOT version. If the base branch was just released, wait for the automated 'next SNAPSHOT' PR to merge first."
exit 1
fi
fi
- name: Ensure (strict) monotony of the version
run: |
TMP_POM=$(mktemp)
HTTP_STATUS=$(curl -s -w "%{http_code}" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
-o "$TMP_POM" \
"https://api.github.com/repos/${{ github.repository }}/contents/pom.xml?ref=${{ github.base_ref }}")
if [ "$HTTP_STATUS" -ne 200 ]; then
echo "Warning: pom.xml not found in ${{ github.base_ref }}. HTTP status: $HTTP_STATUS."
echo "Information: We assume the base branch is new and does not contain a pom.xml yet."
rm "$TMP_POM"
exit 0
fi
echo "Base branch pom.xml downloaded successfully."
# hint: unfortunately mvn (as used above) fails if the downloaded pom is an aggregator pom and needs child poms as well
LATEST_VERSION=$(grep -m1 '<version>' $TMP_POM | sed -E 's/.*<version>(.+)<\/version>.*/\1/')
rm "$TMP_POM"
# did the version not change? if not: release branches fail (they must bump), other branches: ok
if [ "$LATEST_VERSION" == "${{ env.PROPOSED_VERSION }}" ]; then
if [[ "${{ github.head_ref }}" != release/prep-* ]]; then
echo "No version change necessary on ${{ github.head_ref }}.";
exit 0
else
echo "Version change necessary on a release branch (release/prep-*)!";
exit 1
fi
fi
# is the new version higher? hint: does not handle 0.1.3-alpha versions.. just numbers! (or both with the same suffix like -SNAPHSOT)
if [ "$(printf "%s\n%s" "${{ env.PROPOSED_VERSION }}" "$LATEST_VERSION" | sort -V | head -n1)" = "${{ env.PROPOSED_VERSION }}" ]; then
echo "Proposed new version is lower than the latest version!"
echo "${{ env.PROPOSED_VERSION }} <= $LATEST_VERSION"
exit 1
fi