Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
releaseType: maven
handleGHRelease: true
bumpMinorPreMajor: false
extraFiles:
- core/src/main/java/com/google/adk/Version.java
1 change: 1 addition & 0 deletions .github/release-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enabled: true
62 changes: 62 additions & 0 deletions .github/workflows/pr-commit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# .github/workflows/pr-commit-check.yml
# This GitHub Action workflow checks if a pull request has more than one commit.
# If it does, it fails the check and instructs the user to squash their commits.

name: 'PR Commit Check'

# This workflow runs on pull request events.
# It's configured to run on any pull request that is opened or synchronized (new commits pushed).
on:
pull_request:
types: [opened, synchronize]

# Defines the jobs that will run as part of the workflow.
jobs:
check-commit-count:
# The type of runner that the job will run on. 'ubuntu-latest' is a good default.
runs-on: ubuntu-latest

# The steps that will be executed as part of the job.
steps:
# Step 1: Check out the code
# This action checks out your repository under $GITHUB_WORKSPACE, so your workflow can access it.
- name: Checkout Code
uses: actions/checkout@v4
with:
# We need to fetch all commits to accurately count them.
# '0' means fetch all history for all branches and tags.
fetch-depth: 0

# Step 2: Count the commits in the pull request
# This step runs a script to get the number of commits in the PR.
- name: Count Commits
id: count_commits
# We use `git rev-list --count` to count the commits.
# ${{ github.event.pull_request.base.sha }} is the commit SHA of the base branch.
# ${{ github.event.pull_request.head.sha }} is the commit SHA of the head branch (the PR branch).
# The '..' syntax gives us the list of commits in the head branch that are not in the base branch.
# The output of the command (the count) is stored in a step output variable named 'count'.
run: |
count=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }})
echo "commit_count=$count" >> $GITHUB_OUTPUT

# Step 3: Check if the commit count is greater than 1
# This step uses the output from the previous step to decide whether to pass or fail.
- name: Check Commit Count
# This step only runs if the 'commit_count' output from the 'count_commits' step is greater than 1.
if: steps.count_commits.outputs.commit_count > 1
# If the condition is met, the workflow will exit with a failure status.
run: |
echo "This pull request has ${{ steps.count_commits.outputs.commit_count }} commits."
echo "Please squash them into a single commit before merging."
echo "You can use git rebase -i HEAD~N"
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."
echo "Because you have rewritten the commit history, you must use the --force flag to update the pull request: git push --force"
exit 1

# Step 4: Success message
# This step runs if the commit count is not greater than 1 (i.e., it's 1).
- name: Success
if: steps.count_commits.outputs.commit_count <= 1
run: |
echo "This pull request has a single commit. Great job!"
32 changes: 6 additions & 26 deletions core/src/main/java/com/google/adk/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,13 @@

package com.google.adk;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Tracks the current ADK version. Useful for tracking headers. Kept as a string literal to avoid
* coupling with the build system.
*/
public final class Version {
private static final Logger logger = LoggerFactory.getLogger(Version.class);

public static final String JAVA_ADK_VERSION;

static {
String version = "unknown";
try (InputStream input =
Version.class.getClassLoader().getResourceAsStream("version.properties")) {
if (input != null) {
Properties properties = new Properties();
properties.load(input);
version = properties.getProperty("version", "unknown");
} else {
logger.warn("version.properties file not found in classpath");
}
} catch (IOException e) {
logger.warn("Failed to load version from properties file", e);
}
JAVA_ADK_VERSION = version;
}
// Don't touch this, release-please should keep it up to date.
public static final String JAVA_ADK_VERSION = "0.2.1-SNAPSHOT";

private Version() {}
}
1 change: 0 additions & 1 deletion core/src/main/resources/version.properties

This file was deleted.