Repository navigation
100 lines (90 loc) · 4.08 KB
/
Copy pathrelease.yml
File metadata and controls
100 lines (90 loc) · 4.08 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
name: Release
on:
push:
branches: [main]
paths: [gradle.properties]
workflow_dispatch:
permissions:
contents: write
issues: write
pull-requests: read
jobs:
release:
name: Tag and release
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
fetch-depth: 0
persist-credentials: false
- name: Read version
id: version
run: |
version=$(grep '^VERSION_NAME=' gradle.properties | cut -d= -f2)
# AndroidX-style versions only: 1.2.0, or 1.2.0-alpha01 / -beta01 / -rc01 for pre-releases.
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-(alpha|beta|rc)[0-9]{2})?$ ]]; then
echo "::error::VERSION_NAME=${version} isn't X.Y.Z or X.Y.Z-(alpha|beta|rc)NN"
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
if [[ "$version" == *-* ]]; then echo "prerelease=true" >> "$GITHUB_OUTPUT"; else echo "prerelease=false" >> "$GITHUB_OUTPUT"; fi
if git rev-parse -q --verify "refs/tags/v${version}" >/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "v${version} is already released"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad
if: steps.version.outputs.exists == 'false'
with:
distribution: temurin
java-version: 17
- uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c
if: steps.version.outputs.exists == 'false'
- name: Build and test
if: steps.version.outputs.exists == 'false'
run: ./gradlew ktlintCheck lintRelease apiCheck assembleRelease testDebugUnitTest publishToMavenLocal
- name: Release notes from CHANGELOG.md
if: steps.version.outputs.exists == 'false'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
awk -v v="$VERSION" '
$0 ~ "^## \\[" v "\\]" { found = 1; next }
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md > notes.md
if [ ! -s notes.md ]; then echo "See CHANGELOG.md" > notes.md; fi
# Published before tagging, so a failed upload can be retried without a dangling tag.
- name: Publish to Maven Central
if: steps.version.outputs.exists == 'false'
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }}
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
- name: Create tag and GitHub release
if: steps.version.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
run: |
flags=()
if [ "$PRERELEASE" = "true" ]; then flags+=(--prerelease); fi
gh release create "v${VERSION}" --target "${GITHUB_SHA}" --title "v${VERSION}" --notes-file notes.md "${flags[@]}"
- name: Close milestone
if: steps.version.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.version.outputs.version }}
run: |
# Close the vX.Y.Z milestone, or rename and close a "Next release" one. Pre-releases leave it open.
if [[ "$VERSION" == *-* ]]; then exit 0; fi
number=$(gh api "repos/${GITHUB_REPOSITORY}/milestones?state=open" \
--jq "[.[] | select(.title == \"v${VERSION}\" or .title == \"Next release\")][0].number // empty")
if [ -n "$number" ]; then
gh api -X PATCH "repos/${GITHUB_REPOSITORY}/milestones/${number}" -f title="v${VERSION}" -f state=closed
fi