-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (134 loc) · 6.27 KB
/
Copy pathjdeploy.yml
File metadata and controls
155 lines (134 loc) · 6.27 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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# This workflow builds the Java project with Maven and publishes native app installers to
# GitHub Releases via jDeploy (https://www.jdeploy.com).
#
# Flow: push to develop -> job 1 tags "1.0.<commit count>" -> tag push -> job 2 builds + publishes.
# The tag is required: the jDeploy action only creates a versioned release for tag pushes. On a
# branch push it instead publishes a rolling prerelease named after the branch at version
# "0.0.0-<branch>".
#
# Needs the ADM_JDEPLOY_GITHUB_TOKEN secret (a personal access token with contents:write).
# See README.md -> "Releasing" for how to create it.
name: build and deploy using jDeploy
on:
push:
branches: ['develop']
# IMPORTANT: only version tags - must NOT match 'jdeploy'. jDeploy creates a tag by that name
# in this repo to hold package-info.json, and 'tags: [*]' would re-trigger this workflow on it,
# publishing a bogus release with version "jdeploy" and pointing dist-tags.latest at it.
tags: ['1.0.*']
# NOTE: path filters are ignored for tag pushes, so this only skips job 1
paths-ignore:
- 'README.md'
workflow_dispatch:
concurrency:
group: jdeploy-release-${{ github.repository }}
cancel-in-progress: false
# needed to create tags and releases
permissions:
contents: write
jobs:
# ==========================================
# JOB 1: tag on merge to develop
# ==========================================
tag-release:
if: ${{ github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/develop' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# CRITICAL: must use a PAT here. Pushes made with the default GITHUB_TOKEN don't
# trigger workflows, so the 'build-and-deploy' job below would never run.
token: ${{ secrets.ADM_JDEPLOY_GITHUB_TOKEN }}
fetch-depth: 0
- name: Get Version and Push Tag
run: |
COMMIT_COUNT=$(git rev-list --count HEAD)
VERSION="1.0.${COMMIT_COUNT}"
echo "Calculated version: $VERSION"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "✅ Tag $VERSION already exists. No new release needed."
else
echo "▶ Creating and pushing new tag: $VERSION"
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git tag "$VERSION"
git push origin "$VERSION"
fi
# ==========================================
# JOB 2: build and deploy (triggered by tag)
# ==========================================
build-and-deploy:
# second guard against publishing jDeploy's own metadata tag as if it were a release
if: ${{ github.ref_type == 'tag' && github.ref_name != 'jdeploy' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# full history so gen_release_notes.sh can log commits back to the previous tag
fetch-depth: 0
- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: '22'
distribution: 'temurin'
cache: maven
- name: Build with Maven
# pass the tag in as the version so app.properties matches the release
run: mvn -B package --file pom.xml -Drevision=${{ github.ref_name }}
# publishes to https://github.com/jpage4500/AndroidDeviceManager/releases
# - uploads mac/windows/linux installers as release assets
# - updates package-info.json on the 'jdeploy' tag (used by installed apps to auto-update)
- name: Publish release to GitHub
uses: shannah/jdeploy@master
with:
github_token: ${{ secrets.ADM_JDEPLOY_GITHUB_TOKEN }}
deploy_target: 'github'
# also attach the fat jar - see SERVER.md for running ADM headless
# NOTE: uploaded with the CLI (not an action) so the release body jDeploy just wrote is left alone
- name: Attach jar to release
env:
GH_TOKEN: ${{ secrets.ADM_JDEPLOY_GITHUB_TOKEN }}
run: |
gh release upload "${{ github.ref_name }}" target/AndroidDeviceManager.jar \
--repo "${{ github.repository }}" --clobber
- name: Generate Release Notes
env:
# only used to look up PR titles for merge commits; read-only access is enough
GITHUB_TOKEN: ${{ github.token }}
run: |
chmod +x scripts/gen_release_notes.sh
./scripts/gen_release_notes.sh "pr" "brief" > notes.raw
# drop blank lines and empty-subject commits, then normalize to "- " markdown bullets
grep -v '^[[:space:]]*$' notes.raw \
| grep -viE '^[[:space:]]*-?[[:space:]]*no message[[:space:]]*$' \
| sed -E 's/^[[:space:]]*-[[:space:]]*//; s/^/- /' > release-notes.txt
if [[ ! -s release-notes.txt ]]; then
echo "- no changes" > release-notes.txt
fi
echo "Generated Release Notes:"
cat release-notes.txt
# view releases here: https://github.com/jpage4500/AndroidDeviceManager/releases
# jDeploy already wrote the installer download links into the body - keep them and add
# the release notes above
#
# IMPORTANT: --draft=false is required. jDeploy uploads tag releases via
# xresloader/upload-to-github-release, which defaults draft=true and jDeploy never overrides
# it - so the release is created hidden and its assets 404 for the launcher.
- name: Publish GitHub Release with notes
env:
GH_TOKEN: ${{ secrets.ADM_JDEPLOY_GITHUB_TOKEN }}
run: |
EXISTING=$(gh release view "${{ github.ref_name }}" \
--repo "${{ github.repository }}" \
--json body -q '.body' || echo "")
# if the body couldn't be read, fall back to the installer links jdeploy generated
INSTALLER_LINKS=./jdeploy/github-release-files/jdeploy-release-notes.md
if [[ -z "$EXISTING" && -f "$INSTALLER_LINKS" ]]; then
EXISTING=$(cat "$INSTALLER_LINKS")
fi
{ echo "## Release Notes"; echo ""; cat release-notes.txt; echo ""; echo "$EXISTING"; } > combined-notes.txt
gh release edit "${{ github.ref_name }}" \
--notes-file combined-notes.txt \
--draft=false \
--latest \
--repo "${{ github.repository }}"