-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: update hermetic library generation workflow #10693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
ae8e207
b20b0c5
8cef63a
018be46
003a3e2
932d1a1
8a4293e
064fff2
9ffd66d
19c7912
cca96ea
11e2255
314d136
fc85560
9b612c8
3acdfde
102b46c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
name: Hermetic library generation upon generation config change through pull requests | ||
on: | ||
pull_request: | ||
types: | ||
- synchronize | ||
paths: | ||
- generation_config.yaml | ||
- "generation_config.yaml" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the trigger only for main branch? If yes, can this be configured to be triggered for other branches, like a future LTS branch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be triggered when a pull request changes Therefore, it can be used in any branch since the pull request is not necessarily based on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any configuration for a target branch, does it mean if I create a PR with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. |
||
jobs: | ||
library_generation: | ||
runs-on: ubuntu-latest | ||
|
@@ -14,14 +12,59 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 | ||
- name: checkout the target branch | ||
shell: bash | ||
run: | | ||
git checkout ${{ github.base_ref }} | ||
- name: checkout the current branch | ||
shell: bash | ||
run: | | ||
git checkout ${{ github.head_ref }} | ||
- name: get baseline generation config | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.base_ref }} | ||
path: baseline | ||
sparse-checkout: generation_config.yaml | ||
- name: diff | ||
shell: bash | ||
run: | | ||
diff generation_config.yaml baseline/generation_config.yaml | ||
git show ${{ github.base_ref }}:generation_config.yaml > baseline_generation_config.yaml | ||
- name: show configuration diff | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we extract most of the logics here to a shell script so that we can call the script directly here? That way we can easily call it in local and possibly in a non-Github environment in the future. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved command lines to a script. |
||
shell: bash | ||
run: | | ||
diff generation_config.yaml baseline_generation_config.yaml || echo "config diff" | ||
- name: create a docker volume | ||
shell: bash | ||
run: | | ||
set -x | ||
# we create a volume pointing to `pwd` (google-cloud-java) that will | ||
# be referenced by the container and its children | ||
if [[ $(docker volume inspect repo-google-cloud-java) != '[]' ]]; then | ||
docker volume rm repo-google-cloud-java | ||
fi | ||
docker volume create --name "repo-google-cloud-java" --opt "type=none" --opt "device=$(pwd)" --opt "o=bind" | ||
- name: generate changed libraries | ||
shell: bash | ||
run: | | ||
docker run --rm \ | ||
${repo_volumes} \ | ||
-v /tmp:/tmp \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-e "RUNNING_IN_DOCKER=true" \ | ||
-e "REPO_BINDING_VOLUMES=${repo_volumes}" \ | ||
gcr.io/cloud-devrel-public-resources/java-library-generation:"${library_generation_image_tag}" \ | ||
python /src/cli/entry_point.py generate \ | ||
--baseline-generation-config-path=/workspace/google-cloud-java/baseline_generation_config.yaml \ | ||
--current-generation-config-path=/workspace/google-cloud-java/generation_config.yaml \ | ||
--repository-path=/workspace/google-cloud-java | ||
- name: push commit to the pull request | ||
shell: bash | ||
run: | | ||
[ -z "`git config user.email`" ] && git config --global user.email "[email protected]" | ||
[ -z "`git config user.name`" ] && git config --global user.name "cloud-java-bot" | ||
git add java-* pom.xml gapic-libraries-bom/pom.xml versions.txt generation_config.yaml | ||
message="chore: generate libraries at $(date)" | ||
git commit --allow-empty -m "${message}" | ||
git push -f | ||
if [[ -f "pr_description.txt" ]]; then | ||
pr_num=$(gh pr list -s open -H ${{ github.head_ref }} -q . --json number | jq ".[] | .number") | ||
gh pr edit "${pr_num}" --body "$(cat pr_description.txt)" | ||
fi | ||
env: | ||
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Update googleapis commit | ||
on: | ||
schedule: | ||
- cron: '* 2 * * *' | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
update-googleapis-commit: | ||
runs-on: ubuntu-22.04 | ||
env: | ||
# the branch into which the pull request is merged | ||
base_branch: main | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup branch for pull request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above. Let's extract it to a script for now, and think about ways to make it more reusable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved command lines to a script. |
||
shell: bash | ||
run: | | ||
[ -z "`git config user.email`" ] && git config --global user.email "[email protected]" | ||
[ -z "`git config user.name`" ] && git config --global user.name "cloud-java-bot" | ||
# try to find a open pull request associated with the branch | ||
pr_num=$(gh pr list -s open -H "generate-libraries-${base_branch}" -q . --json number | jq ".[] | .number") | ||
# create a branch if there's no open pull request associated with the | ||
# branch; otherwise checkout the pull request. | ||
if [ -z "${pr_num}" ]; then | ||
git checkout -b "generate-libraries-${base_branch}" | ||
else | ||
gh pr checkout "${pr_num}" | ||
fi | ||
echo "pr_num=${pr_num}" >> "$GITHUB_ENV" | ||
env: | ||
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }} | ||
- name: Update googleapis commit to latest | ||
shell: bash | ||
run: | | ||
mkdir tmp-googleapis | ||
# use partial clone because only commit history is needed. | ||
git clone --filter=blob:none https://github.com/googleapis/googleapis.git tmp-googleapis | ||
pushd tmp-googleapis | ||
git pull | ||
latest_commit=$(git rev-parse HEAD) | ||
popd | ||
rm -rf tmp-googleapis | ||
sed -i -e "s/^googleapis_commitish.*$/googleapis_commitish: ${latest_commit}/" generation_config.yaml | ||
- name: create or update the pull request | ||
shell: bash | ||
run: | | ||
title="chore: update googleapis commit at $(date)" | ||
git add generation_config.yaml | ||
# use --allow-empty because (rarely) there's no change. | ||
git commit --allow-empty -m "${title}" | ||
if [ -z "${pr_num}" ]; then | ||
git remote add monorepo https://cloud-java-bot:${GH_TOKEN}@github.com/${{ github.repository }}.git | ||
git fetch -q --unshallow monorepo | ||
git push -f monorepo "generate-libraries-${base_branch}" | ||
gh pr create --title "${title}" --head "generate-libraries-${base_branch}" --body "${title}" --base "${base_branch}" | ||
else | ||
git push | ||
fi | ||
env: | ||
GH_TOKEN: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }} | ||
pr_num: ${{ env.pr_num }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
ommited
should beomitted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.