Skip to content

Commit d064ff6

Browse files
committed
Protect spring-cherry-pick against pushing commit to itself
The `Auto-cherry-pick` commit may be pushed into a branch for which the cherry-pick is supposed to happen. So, check in loop for `$branches` if requested branch is not exactly same where the commit has been just pushed. * Fix typos and some sentence in the `README.md` according to the current state of things.
1 parent 31aabdb commit d064ff6

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

.github/workflows/spring-cherry-pick.yml

+12-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ jobs:
3939
branches=$(echo "$COMMIT_MESSAGE" | grep "$CHERRY_PICK_TOKEN" | grep -o1 -E "([0-9]+\.[0-9]+\.x)")
4040
for branch in $branches
4141
do
42-
git checkout "$branch"
43-
if git cherry-pick ${{ github.sha }} -x
42+
if [ "$branch" != '${{ github.ref_name }}' ]
4443
then
45-
echo "::notice title=Commit cherry-picked::${{ github.sha }} to branch $branch"
46-
else
47-
echo "::error title=Cannot cherry-pick::${{ github.sha }} to branch $branch. Manual procedure required"
48-
exit 1
44+
git checkout "$branch"
45+
if git cherry-pick ${{ github.sha }} -x
46+
then
47+
echo "::notice title=Commit cherry-picked::${{ github.sha }} to branch $branch"
48+
else
49+
echo "::error title=Cannot cherry-pick::${{ github.sha }} to branch $branch. Manual procedure required"
50+
exit 1
51+
fi
52+
branchCommitMessage=$(git log -1 --pretty=%B | grep -v "$CHERRY_PICK_TOKEN")
53+
git commit --amend -o -m "$branchCommitMessage"
54+
git push origin $branch
4955
fi
50-
branchCommitMessage=$(git log -1 --pretty=%B | grep -v "$CHERRY_PICK_TOKEN")
51-
git commit --amend -o -m "$branchCommitMessage"
52-
git push origin $branch
5356
done

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GitHub Actions Workflows for Spring Projects
22

3-
This project containers reusable GitHub Actions Workflows to build Spring projects with Gradle or Maven.
3+
This project contains reusable GitHub Actions Workflows to build Spring projects with Gradle or Maven.
4+
And provides some other useful utilities to perform from GitHub Actions, such a Dependabot auto-merge, or automatic back-port issue creation.
45
The workflows are designed for specific tasks and can be reused individually or in combinations in the target projects.
56

67
To use these workflows in your project a set of organization secrets must be granted to the repository:
@@ -19,13 +20,13 @@ GPG_PASSPHRASE
1920
GPG_PRIVATE_KEY
2021
```
2122

22-
The Develocity secret is optional: not used by Maven and Gradle project might not be enrolled for the service.
23+
The Develocity secret is optional: mostly not used by Maven and Gradle project might not be enrolled for the service.
2324
The `SPRING_RELEASE_CHAT_WEBHOOK_URL` secret is also optional: probably you don't want to notify Google Space about your release, or it is not available for GitHub organization.
2425
As well as `OSSRH_*` secret, since not all releases might go to Maven Central, e.g. private (commercial) repositories only.
2526

2627
The mentioned secrets must be passed explicitly since these reusable workflows might be in different GitHub org than target project.
2728

28-
The SNAPSHOT and Release workflows uses JFrog Artifactory plugin to publish artifacts into Artifactory.
29+
The SNAPSHOT and Release workflows uses [spring-io/artifactory-deploy-action](https://github.com/spring-io/artifactory-deploy-action) to publish artifacts into Artifactory.
2930

3031
## Build SNAPSHOT and Pull Request Workflows
3132

@@ -42,8 +43,8 @@ https://github.com/spring-io/spring-github-workflows/blob/78b29123a17655f019d800
4243
You can add more branches to react for pull request events.
4344

4445
The SNAPSHOT workflows ([spring-artifactory-gradle-snapshot.yml](.github/workflows/spring-artifactory-gradle-snapshot.yml) and [spring-artifactory-maven-snapshot.yml](.github/workflows/spring-artifactory-maven-snapshot.yml), respectively) are also that simple.
45-
They use JFrog Artifactory plugin to be able to publish artifacts into `libs-snapshot-local` (by default) repository.
46-
The Gradle workflow can be supplied with Gradle Enterprise secrets.
46+
They publish artifacts into `libs-snapshot-local` (by default) repository.
47+
The Gradle workflow can be supplied with Develocity secret.
4748

4849
#### Gradle SNAPSHOT caller workflow:
4950
https://github.com/spring-io/spring-github-workflows/blob/78b29123a17655f019d800690cc906d692f836a9/samples/ci-snapshot-gradle.yml#L1-L18

0 commit comments

Comments
 (0)