Repository navigation
88 lines (79 loc) · 2.8 KB
/
Copy pathci.yml
File metadata and controls
88 lines (79 loc) · 2.8 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
name: CI
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build and Test
run: mvn clean test post-integration-test
# Tags and releases the version declared in pom.xml once it reaches the
# default branch. A version that is already tagged is left alone.
release:
needs: test
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
outputs:
tag: ${{ steps.version.outputs.tag }}
created: ${{ steps.release.outputs.created }}
steps:
- uses: actions/checkout@v4
- name: Read the version from pom.xml
id: version
run: |
VERSION=$(awk '/<artifactId>ipdata-java-client<\/artifactId>/{f=1} f&&/<version>/{sub(/.*<version>/,"");sub(/<\/version>.*/,"");print;exit}' pom.xml)
if [ -z "$VERSION" ]; then
echo "::error file=pom.xml::Could not read the project version"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag=v$VERSION" >> "$GITHUB_OUTPUT"
- name: Create the tag and the GitHub release
id: release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
status=0
git ls-remote --exit-code --tags origin "refs/tags/$TAG" > /dev/null || status=$?
if [ "$status" -eq 0 ]; then
echo "Tag $TAG already exists; nothing to release."
echo "created=false" >> "$GITHUB_OUTPUT"
exit 0
elif [ "$status" -ne 2 ]; then
echo "::error::git ls-remote failed with status $status"
exit "$status"
fi
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
echo "Created tag and release $TAG."
echo "created=true" >> "$GITHUB_OUTPUT"
# A tag created with the workflow token does not trigger the Release
# workflow on its own, so the Maven Central deploy runs in this run.
publish:
needs: release
if: needs.release.outputs.created == 'true'
uses: ./.github/workflows/release.yml
with:
tag: ${{ needs.release.outputs.tag }}
secrets: inherit