Skip to content

Commit

Permalink
fix(actions/gapic): only push if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt committed Mar 18, 2020
1 parent 6a66a93 commit 3f38e4f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test Actions
on:
push:
schedule:
- cron: '0 * * * *'
jobs:
gapic:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Run the gapic action
uses: ./actions/gapic
with:
target: //google/maps/routes/v1:gapic-maps-routes-v1-go
github_token: ${{ secrets.GITHUB_TOKEN }}
tar_path: gapic-maps-routes-v1-go/cloud.google.com/go/maps
tar_strip_components: 4
cache_service_account: ${{ secrets.SERVICE_ACCOUNT_CACHE }}
28 changes: 19 additions & 9 deletions actions/gapic/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bazel build $INPUT_TARGET

popd

#### PUBLISH CHANGES ####
#### MAKE LOCAL CHANGES ####

pushd $TEMP_GIT_LOCAL

Expand All @@ -46,17 +46,27 @@ git reset --hard origin/master
# extract the tar to the correct location
tar xf "${TEMP_GIT_GOOGLEAPIS}/bazel-bin/${TARGET_OUTPUT}" --strip-components $INPUT_TAR_STRIP_COMPONENTS $INPUT_TAR_PATH

# commit the changes if any to the branch
if [[ -n $(git status -s -uall) ]]; then
#### PUBLISH COMMITS ####

[[ -n $(git diff "origin/master") ]] && differs_from_master=1 || differs_from_master=0

if [ $differs_from_master ]; then
git add -A
git commit -m 'feat: regenerate gapic'
git push -f -u origin $BRANCH

curl \
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \
-H "Content-Type:application/json" \
-X POST https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls \
-d "{\"title\":\"GAPIC Client Update: ${INPUT_TARGET}\", \"body\": \"\", \"head\": \"$BRANCH\", \"base\": \"master\"}"
[[ -n $(git ls-remote --heads origin ${BRANCH}) ]] && has_branch=1 || has_branch=0
[[ -n $(git diff "origin/${BRANCH}") ]] && differs_from_branch=1 || differs_from_branch=0

if [[ !$has_branch || $differs_from_branch ]]; then
git push -f -u origin $BRANCH

curl \
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \
-H "Content-Type:application/json" \
-X POST https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls \
-d "{\"title\":\"GAPIC Client Update: ${INPUT_TARGET}\", \"body\": \"\", \"head\": \"$BRANCH\", \"base\": \"master\"}"
fi

fi

popd

0 comments on commit 3f38e4f

Please sign in to comment.