-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (106 loc) · 4.05 KB
/
ci-and-release.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
name: Run cached tests
# Build script adopted from itemstack-count-infrastructure
# https://github.com/kory33/itemstack-count-infrastructure/blob/22721250c3e8bb2688538e3933a5f5f998406c2c/.github/workflows/create-release.yml
on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- '*'
jobs:
lint_and_test:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare build dependencies cache
uses: ./.github/actions/cache-build-dependencies
with:
cache-version: v-4
- name: Prepare build cache
uses: ./.github/actions/cache-builds
with:
cache-version: v-3
- name: Lint and Test
run: sbt "scalafmtCheckAll; compile; scalafixAll --check; test"
publish:
runs-on: ubuntu-22.04
# we wish to publish on tags (non-SNAPSHOT versions)
# and on master branch (SNAPSHOT versions) as long as lint_and_test passed
needs: lint_and_test
if: ${{ startsWith(github.ref, 'refs/tags/v') || (github.ref == 'refs/heads/master') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Prepare build dependencies cache
uses: ./.github/actions/cache-build-dependencies
with:
cache-version: v-3
- name: Prepare build cache
uses: ./.github/actions/cache-builds
with:
cache-version: v-2
- name: Import signing PGP key
env:
PGP_SECRET: ${{ secrets.PGP_SECRET }}
run: |
gpg --version
echo "$PGP_SECRET" | gpg --import
- name: Publish SNAPSHOT artifacts to Sonatype
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: sbt publishSigned
- name: Publish non-SNAPSHOT version to Maven central
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
DECLARED_VERSION="$(grep -oP "(?<=ThisBuild / version := \")((\d+\.)+\d+)(?=-SNAPSHOT\")" build.sbt)"
TAGGED_VERSION=$(echo ${{ github.ref }} | sed -e "s~^refs/tags/v~~")
if [ "$DECLARED_VERSION" != "$TAGGED_VERSION" ]; then
echo "Found $DECLARED_VERSION on build.sbt, but tagged $TAGGED_VERSION. Exiting..."
exit 1
fi
# set the artifact version to DECLARED_VERSION
sed -i -e "s~ThisBuild / version := \".*\"~ThisBuild / version := \"$DECLARED_VERSION\"~" build.sbt
# publish to local repository, and then release bundle
sbt "publishSigned; sonatypeBundleRelease"
create-github-release:
runs-on: ubuntu-latest
# when we published a non-SNAPSHOT version
needs: publish
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get the version
id: get_version
run: echo "::set-output name=VERSION::${GITHUB_REF#refs/tags/}"
- name: Get commit summary
id: get_commit_summary
run: |
PREVIOUS_TAG="$(git tag --sort=-creatordate | sed -n 2p)"
echo "PREVIOUS_TAG: $PREVIOUS_TAG"
COMMIT_SUMMARY="$(git log --oneline --pretty=tformat:"%h %s" "$PREVIOUS_TAG..${{ github.ref }}")"
COMMIT_SUMMARY="${COMMIT_SUMMARY//$'\n'/'%0A'}"
echo "::set-output name=COMMIT_SUMMARY::$COMMIT_SUMMARY"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }}
body: |
${{ steps.get_commit_summary.outputs.COMMIT_SUMMARY }}
draft: false
prerelease: false