Repository navigation
Expand file tree
/
Copy pathjava-github-release-template.yml
More file actions
124 lines (123 loc) · 4.99 KB
/
Copy pathjava-github-release-template.yml
File metadata and controls
124 lines (123 loc) · 4.99 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
# SPDX-FileCopyrightText: Copyright (C) 2025-2026 Fabrício Barros Cabral
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
name: java-github-release-template
'on':
workflow_call:
inputs:
working-directory:
description: "Set the working directory"
required: false
default: "."
type: string
defaults:
run:
shell: bash -xeuo pipefail {0}
permissions:
actions: read
security-events: write
contents: write
packages: write
jobs:
java-github-release-template:
runs-on: ubuntu-latest
steps:
- name: Check workflow status
uses: actions/github-script@v9
with:
script: |
const { data: branch } = await github.rest.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
branch: 'main',
});
const sha = branch.commit.sha;
const { data } = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const runs = data.workflow_runs
.filter(run => run.head_sha === branch.commit.sha)
.filter(run => run.id !== context.runId)
.filter(run => !run.name.toLowerCase().includes('release'));
const pending = runs.some(run => run.conclusion === null);
if (pending) {
core.setFailed('Some workflows are still running');
}
const failed = runs.some(run => run.conclusion === 'failure');
if (failed) {
core.setFailed(
'I cant release a new version because some workflows failed'
);
}
- name: Checkout repository
uses: actions/checkout@v7
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ github.ref }}
- name: Fix detached HEAD
run: |
git checkout -B "${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
- name: Setup Java SDK
uses: actions/setup-java@v6
with:
distribution: 'temurin'
java-version: 25.0.4+101.0.LTS
- name: Configure Maven cache
uses: actions/cache@v6
with:
path: ~/.m2/repository
key: ${{ runner.os }}-jdk-21-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-jdk-21-maven-
- name: Download and install xmlstarlet
working-directory: ${{ inputs.working-directory }}
run: |
sudo DPKG_PROGRESS_FD=0 apt-get -y -qq update
sudo DPKG_PROGRESS_FD=0 apt-get install -y -qq xmlstarlet
- name: Configure Git
working-directory: ${{ inputs.working-directory }}
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- name: Setup Maven settings.xml
working-directory: ${{ inputs.working-directory }}
run: |
# Set settings.xml path
settings="${HOME}/.m2/settings.xml"
# Add 'github-packages' server
xmlstarlet ed -L \
-s "/*[local-name()='settings']/*[local-name()='servers']" \
-t elem -n "server" -v "" \
-s "/*[local-name()='settings']/*[local-name()='servers']/server[last()]" \
-t elem -n "id" -v "github-packages" \
-s "/*[local-name()='settings']/*[local-name()='servers']/server[last()]" \
-t elem -n "username" -v "\${env.GITHUB_ACTOR}" \
-s "/*[local-name()='settings']/*[local-name()='servers']/server[last()]" \
-t elem -n "password" -v "\${env.GITHUB_TOKEN}" \
"${settings}"
- name: Deploy to Github Packages
working-directory: ${{ inputs.working-directory }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
[[ "${{ github.ref_name }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || exit 1
[[ -x "mvnw" ]] && mvn="./mvnw" || mvn="mvn"
${mvn} help:all-profiles | grep -q "github-packages" \
|| { echo "Error: 'github-packages' profile not found in pom.xml"; exit 1; }
${mvn} versions:set "-DnewVersion=${{ github.ref_name }}"
git commit -am "Release ${{ github.ref_name }}"
${mvn} deploy -Pgithub-packages --errors --batch-mode
- name: Publish to GitHub Releases
uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
files: |
${{ inputs.working-directory }}/target/${{ github.event.repository.name }}-${{ github.ref_name }}.jar
${{ inputs.working-directory }}/target/${{ github.event.repository.name }}-${{ github.ref_name }}-sources.jar
${{ inputs.working-directory }}/target/${{ github.event.repository.name }}-${{ github.ref_name }}-javadoc.jar