Repository navigation
143 lines (140 loc) · 7.62 KB
/
Copy pathrelease-please.yml
File metadata and controls
143 lines (140 loc) · 7.62 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
name: Release Please
on:
# A release is cut when a human merges the platform-managed release PR into
# main (the PR's base, so its diff shows the full pending release).
# Every other push here runs release-please as well — commits written straight to
# this branch included — and cuts nothing, there being no release commit at the tip.
push:
branches:
- main
# The Scalar platform pushes these workflow files straight to main to keep them
# current between releases; that is bookkeeping, never a release. Running anyway is worse
# than pointless on a branch that has not been handed a .release-please-manifest.json yet —
# release-please fails the run outright when it cannot read one. A release commit always
# rewrites the manifest and the changelog, so this filter can never swallow one.
paths-ignore:
- '.github/workflows/**'
# Manual fallback only; nothing in the automated chain depends on dispatch.
workflow_dispatch:
permissions:
contents: write
# Required to update the merged release PR's autorelease labels after tagging.
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
# Consumed by the publish job's checkout: without this mapping the checkout ref would be
# empty and the publish would build the triggering branch head instead of the released
# tag's exact commit.
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
id: release
with:
target-branch: main
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
# Release PRs are opened and updated by the Scalar platform with its own
# credential (so their CI runs without manual approval); this workflow only
# cuts the tag + GitHub Release once a release PR is merged.
skip-github-pull-request: true
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: ${{ steps.release.outputs.release_created == 'true' }}
with:
fetch-depth: 0
# Merging the release PR into main is itself the promotion, but the
# version bump and changelog must also land back on scalar-next, or the next
# release PR would propose this release again. A real merge (never a plain
# commit push) so a squash- or rebase-merged release PR syncs just as well; the
# non-conventional message keeps the sync commit out of future changelogs.
#
# The Scalar platform merges main into scalar-next itself when the release
# PR merges, so this step routinely races it. The sync is done once the release commit
# is an ancestor of scalar-next, whoever merged it, so that is checked before every
# attempt. A rejected push retries from a fresh fetch rather than failing the release
# run. Plain (non-force) push on purpose: a concurrent regeneration push is never
# discarded, and a sync that still cannot land after the retries fails loudly.
- name: Sync release back to scalar-next
if: ${{ steps.release.outputs.release_created == 'true' }}
env:
RELEASE_SHA: ${{ steps.release.outputs.sha }}
RELEASE_TAG: ${{ steps.release.outputs.tag_name }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
# Explicit `|| return 1`s because `set -e` does not apply inside a function called
# as a condition, and a failed merge must never fall through to a no-op push.
sync_release() {
git fetch origin scalar-next || return 1
if git merge-base --is-ancestor "$RELEASE_SHA" origin/scalar-next; then
echo "$RELEASE_TAG is already on scalar-next."
return 0
fi
git checkout -B scalar-next origin/scalar-next || return 1
if ! git merge --no-edit -m "Sync release $RELEASE_TAG back to scalar-next" "$RELEASE_SHA"; then
git merge --abort
return 1
fi
git push origin scalar-next
}
for attempt in 1 2 3; do
if sync_release; then exit 0; fi
echo "Attempt $attempt of 3 to sync $RELEASE_TAG back to scalar-next failed."
if [ "$attempt" -lt 3 ]; then sleep $((attempt * 5)); fi
done
echo "::error::Could not sync $RELEASE_TAG back to scalar-next after 3 attempts."
exit 1
publish:
needs: release-please
# `!cancelled()` keeps publishing even when the back-sync to the integration branch
# failed: a raced integration branch must not block the release from reaching its
# registry.
if: ${{ !cancelled() && needs.release-please.outputs.release_created == 'true' }}
runs-on: ubuntu-latest
# Job-level permissions replace the workflow's release-cutting grants with the publish
# floor. OIDC trusted publishing verifies this run's claims, which name this workflow
# file — register release-please.yml as the trusted publisher on the registry.
permissions:
contents: read
id-token: write
packages: write
env:
VERSIONING_POLICY: manual
steps:
# Publishing runs inline — a top-level job of this same run — rather than dispatching
# sdk-release.yml: workflow_dispatch resolves the target workflow on the repository's
# default branch only, so a dispatch would 404 whenever the release line is any other
# branch, while OIDC trusted publishing accepts this job because it stays top-level
# (never a reusable-workflow call). The release-please job cut the tag earlier in this
# run; checking it out publishes exactly the released commit, not the branch head that
# triggered the workflow.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.release-please.outputs.tag_name }}
- uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1
with:
distribution: temurin
java-version: "21"
# `enhanced` (the default) is proprietary — free for public repos, a free preview for
# private. `basic` is MIT `actions/cache` but keeps no restore keys: a dependency change
# rebuilds the cache cold.
- uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
with:
cache-provider: basic
- run: ./gradlew build
- name: Publish to Maven Central
run: |
GROUP_PATH="$(echo 'com.scalar.api' | tr '.' '/')"
VERSION="$(sed -n 's/^[[:space:]]*version = "\(.*\)"$/\1/p' build.gradle.kts | head -n1)"
if curl -sf -A "scalar-sdk-release" -o /dev/null "https://repo1.maven.org/maven2/${GROUP_PATH}/scalar-java/${VERSION}/scalar-java-${VERSION}.pom"; then
echo "com.scalar.api:scalar-java:${VERSION} already on Maven Central, skipping"
else
./gradlew publishToMavenCentral --no-configuration-cache
fi
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME || secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD || secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_GPG_PRIVATE_KEY || secrets.GPG_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_GPG_PASSPHRASE || secrets.GPG_SIGNING_PASSWORD }}