Skip to content

Commit

Permalink
add image tag input to shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeWang1127 committed Nov 15, 2024
1 parent 1a84308 commit ddca0b8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
7 changes: 6 additions & 1 deletion .github/scripts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ inputs:
required: true
image_tag:
description: the tag of hermetic build image
required: true
generator_version:
description: the version of gapic-generator-java
required: false
token:
description: Personal Access Token
Expand Down Expand Up @@ -72,9 +75,11 @@ runs:
bash hermetic_library_generation.sh \
--target_branch "${BASE_REF}" \
--current_branch "${HEAD_REF}" \
--image_tag "${IMAGE_TAG}"
--image_tag "${IMAGE_TAG}" \
--generator_version "${GENERATOR_VERSION}"
env:
BASE_REF: ${{ inputs.base_ref }}
HEAD_REF: ${{ inputs.head_ref }}
IMAGE_TAG: ${{ inputs.image_tag }}
GENERATOR_VERSION: ${{ inputs.generator_version }}
GH_TOKEN: ${{ inputs.token }}
20 changes: 13 additions & 7 deletions .github/scripts/hermetic_library_generation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ set -e
# The parameters of this script is:
# 1. target_branch, the branch into which the pull request is merged.
# 2. current_branch, the branch with which the pull request is associated.
# 3. [optional] image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
# 4. [optional] generation_config, the path to the generation configuration,
# 3. image_tag, the tag of gcr.io/cloud-devrel-public-resources/java-library-generation.
# 4.
# 5. [optional] generation_config, the path to the generation configuration,
# the default value is generation_config.yaml in the repository root.
while [[ $# -gt 0 ]]; do
key="$1"
Expand All @@ -40,6 +41,10 @@ case "${key}" in
image_tag="$2"
shift
;;
--generator_version)
generator_version="$2"
shift
;;
--generation_config)
generation_config="$2"
shift
Expand All @@ -62,15 +67,16 @@ if [ -z "${current_branch}" ]; then
exit 1
fi

if [ -z "${image_tag}" ]; then
echo "missing required argument --image_tag"
exit 1
fi

if [ -z "${generation_config}" ]; then
generation_config=generation_config.yaml
echo "Use default generation config: ${generation_config}"
fi

if [ -z "${image_tag}" ]; then
image_tag=$(grep "gapic_generator_version" "${generation_config}" | cut -d ':' -f 2 | xargs)
fi

workspace_name="/workspace"
baseline_generation_config="baseline_generation_config.yaml"
message="chore: generate libraries at $(date)"
Expand Down Expand Up @@ -102,7 +108,7 @@ docker run \
-u "$(id -u):$(id -g)" \
-v "$(pwd):${workspace_name}" \
-v "${api_def_dir}:${workspace_name}/googleapis" \
-e GENERATOR_VERSION="${image_tag}" \
-e GENERATOR_VERSION="${generator_version}" \
gcr.io/cloud-devrel-public-resources/java-library-generation:"${image_tag}" \
--generation-config-path="${workspace_name}/${generation_config}" \
--library-names="${changed_libraries}" \
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/hermetic_library_generation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ jobs:
shell: bash
run: |
GENERATOR_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl gapic-generator-java)
SHARED_DEPENDENCIES_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl java-shared-dependencies)
echo "GENERATOR_VERSION=${GENERATOR_VERSION}" >> "$GITHUB_ENV"
echo "SHARED_DEPENDENCIES_VERSION=${SHARED_DEPENDENCIES_VERSION}" >> "$GITHUB_ENV"
docker build \
-f .cloudbuild/library_generation/library_generation.Dockerfile \
-t gcr.io/cloud-devrel-public-resources/java-library-generation:"${GENERATOR_VERSION}" \
-t gcr.io/cloud-devrel-public-resources/java-library-generation:"${SHARED_DEPENDENCIES_VERSION}" \
.
- uses: ./.github/scripts
if: env.SHOULD_RUN == 'true'
with:
base_ref: ${{ github.base_ref }}
head_ref: ${{ github.head_ref }}
image_tag: ${{ env.GENERATOR_VERSION }}
image_tag: ${{ env.SHARED_DEPENDENCIES_VERSION }}
generator_version: ${{ env.GENERATOR_VERSION }}
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}

0 comments on commit ddca0b8

Please sign in to comment.