Skip to content

Commit dc657c8

Browse files
Poggeccicopybara-github
authored andcommitted
chore: Add release-please & squash commit actions to facilitate release process
PiperOrigin-RevId: 778639221
1 parent 0431e2b commit dc657c8

File tree

5 files changed

+74
-27
lines changed

5 files changed

+74
-27
lines changed

.github/release-please.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
releaseType: maven
2+
handleGHRelease: true
3+
bumpMinorPreMajor: false
4+
extraFiles:
5+
- core/src/main/java/com/google/adk/Version.java

.github/release-trigger.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enabled: true
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# .github/workflows/pr-commit-check.yml
2+
# This GitHub Action workflow checks if a pull request has more than one commit.
3+
# If it does, it fails the check and instructs the user to squash their commits.
4+
5+
name: 'PR Commit Check'
6+
7+
# This workflow runs on pull request events.
8+
# It's configured to run on any pull request that is opened or synchronized (new commits pushed).
9+
on:
10+
pull_request:
11+
types: [opened, synchronize]
12+
13+
# Defines the jobs that will run as part of the workflow.
14+
jobs:
15+
check-commit-count:
16+
# The type of runner that the job will run on. 'ubuntu-latest' is a good default.
17+
runs-on: ubuntu-latest
18+
19+
# The steps that will be executed as part of the job.
20+
steps:
21+
# Step 1: Check out the code
22+
# This action checks out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
23+
- name: Checkout Code
24+
uses: actions/checkout@v4
25+
with:
26+
# We need to fetch all commits to accurately count them.
27+
# '0' means fetch all history for all branches and tags.
28+
fetch-depth: 0
29+
30+
# Step 2: Count the commits in the pull request
31+
# This step runs a script to get the number of commits in the PR.
32+
- name: Count Commits
33+
id: count_commits
34+
# We use `git rev-list --count` to count the commits.
35+
# ${{ github.event.pull_request.base.sha }} is the commit SHA of the base branch.
36+
# ${{ github.event.pull_request.head.sha }} is the commit SHA of the head branch (the PR branch).
37+
# The '..' syntax gives us the list of commits in the head branch that are not in the base branch.
38+
# The output of the command (the count) is stored in a step output variable named 'count'.
39+
run: |
40+
count=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
41+
echo "commit_count=$count" >> $GITHUB_OUTPUT
42+
43+
# Step 3: Check if the commit count is greater than 1
44+
# This step uses the output from the previous step to decide whether to pass or fail.
45+
- name: Check Commit Count
46+
# This step only runs if the 'commit_count' output from the 'count_commits' step is greater than 1.
47+
if: steps.count_commits.outputs.commit_count > 1
48+
# If the condition is met, the workflow will exit with a failure status.
49+
run: |
50+
echo "This pull request has ${{ steps.count_commits.outputs.commit_count }} commits."
51+
echo "Please squash them into a single commit before merging."
52+
echo "You can use git rebase -i HEAD~N"
53+
echo "...where N is the number of commits you want to squash together. The PR check conveniently tells you this number! For example, if the check says you have 3 commits, you would run: git rebase -i HEAD~3."
54+
echo "Because you have rewritten the commit history, you must use the --force flag to update the pull request: git push --force"
55+
exit 1
56+
57+
# Step 4: Success message
58+
# This step runs if the commit count is not greater than 1 (i.e., it's 1).
59+
- name: Success
60+
if: steps.count_commits.outputs.commit_count <= 1
61+
run: |
62+
echo "This pull request has a single commit. Great job!"

core/src/main/java/com/google/adk/Version.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,13 @@
1616

1717
package com.google.adk;
1818

19-
import java.io.IOException;
20-
import java.io.InputStream;
21-
import java.util.Properties;
22-
import org.slf4j.Logger;
23-
import org.slf4j.LoggerFactory;
24-
19+
/**
20+
* Tracks the current ADK version. Useful for tracking headers. Kept as a string literal to avoid
21+
* coupling with the build system.
22+
*/
2523
public final class Version {
26-
private static final Logger logger = LoggerFactory.getLogger(Version.class);
27-
28-
public static final String JAVA_ADK_VERSION;
29-
30-
static {
31-
String version = "unknown";
32-
try (InputStream input =
33-
Version.class.getClassLoader().getResourceAsStream("version.properties")) {
34-
if (input != null) {
35-
Properties properties = new Properties();
36-
properties.load(input);
37-
version = properties.getProperty("version", "unknown");
38-
} else {
39-
logger.warn("version.properties file not found in classpath");
40-
}
41-
} catch (IOException e) {
42-
logger.warn("Failed to load version from properties file", e);
43-
}
44-
JAVA_ADK_VERSION = version;
45-
}
24+
// Don't touch this, release-please should keep it up to date.
25+
public static final String JAVA_ADK_VERSION = "0.2.1-SNAPSHOT";
4626

4727
private Version() {}
4828
}

core/src/main/resources/version.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)