-
Notifications
You must be signed in to change notification settings - Fork 1
115 lines (101 loc) · 4.46 KB
/
release.yaml
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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version to set. If not provided, the current version''s patch version will be incremented.'
required: false
type: string
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: '0'
- name: "Set up JDK"
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
- name: Build Cache
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
~/.cache/google-cloud-tools-java/jib
# workaround for https://github.com/actions/cache/issues/342
# generate new key for each build to force cache push
key: build-cache-${{ github.run_id }}
# but use restore key to restore the latest pushed cache
restore-keys: |
build-cache-
- name: Calculate new version
id: calculate_new_version
run: |
latest_tag=$(git describe --tags --match "v*" --abbrev=0 $(git rev-list --tags --max-count=1))
if [[ -n "${{ github.event.inputs.version }}" ]]; then
version="${{ github.event.inputs.version }}"
if [[ ! $version == v* ]]; then
version="v$version"
fi
else
version=$(echo $latest_tag | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
fi
echo "previous_version=$latest_tag" >> "$GITHUB_OUTPUT"
echo "previous_release=${latest_tag#v}" >> "$GITHUB_OUTPUT"
echo "new_version=$version" >> "$GITHUB_OUTPUT"
echo "new_release=${version#v}" >> "$GITHUB_OUTPUT"
- name: Create tag
run: |
gh_actor_profile="$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${GITHUB_ACTOR}")"
git config --global user.name "$(printf '%s' "$gh_actor_profile" | jq -r .name)"
git config --global user.email "$(printf '%s' "$gh_actor_profile" | jq -r .email)"
git status
git tag "${{ steps.calculate_new_version.outputs.new_version }}"
- name: Build
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
run: ./gradlew assemble --scan --console=plain --build-cache
- name: Test
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
run: ./gradlew check --scan --console=plain --build-cache
- name: "Push Version Tag"
run: |
echo "Pushing tags to remote"
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git push "${remote_repo}" --tags
echo -e "\nPushed"
- name: Create changelog text
id: changelog
uses: loopwerk/tag-changelog@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.calculate_new_version.outputs.new_version }}
name: ${{ steps.calculate_new_version.outputs.new_release }}
body: ${{ steps.changelog.outputs.changes }}
draft: true
- name: Publish release
env:
VERSIONING_GIT_REF: "refs/tags/${{ steps.calculate_new_version.outputs.new_version }}"
ORG_GRADLE_PROJECT_ossrhSigningKey: "${{ secrets.ossrhSigningKey }}"
ORG_GRADLE_PROJECT_ossrhSigningPassword: "${{ secrets.ossrhSigningPassword }}"
ORG_GRADLE_PROJECT_ossrhPassword: "${{ secrets.ossrhPassword }}"
ORG_GRADLE_PROJECT_ossrhUser: "${{ secrets.ossrhUser }}"
run: ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --scan --console=plain --build-cache
- name: Update README with new version
run: |
sed -i -e 's/${{ steps.calculate_new_version.outputs.previous_release }}/${{ steps.calculate_new_version.outputs.new_release }}/g' README.MD
- name: Commit README and push changes
run: |
echo "Committing new version to README.MD"
git add README.MD
git commit -m "chore: Update README.MD with new version"
remote_repo="https://${{ secrets.MASTER_ACTOR }}:${{ secrets.MASTER_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
git push "${remote_repo}"