Skip to content

Commit

Permalink
feat(actions/gapic): allow ability to ignore changes (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoehnelt authored Mar 30, 2020
1 parent f1e60cc commit 11b1dca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:
- 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 }}
dry_run: true
target: //google/maps/routes/v1:google-maps-routes-v1-java-postprocess
github_token: ${{ secrets.GITHUB_TOKEN_REPO }}
tar_path: google-maps-routes-v1-java
tar_strip_components: 1
cache_service_account: ${{ secrets.CACHE_SERVICE_ACCOUNT }}
ignore: |
gradle/*
gradlew
gradlew.bat
8 changes: 8 additions & 0 deletions actions/gapic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Service account json string for Bazel cache.

Bucket name for Bazel cache.

### `ignore`

Files to keep out of staging.

### `dry_run`

Run without writes to repo.
Expand All @@ -50,4 +54,8 @@ uses: googlemaps/actions/gapic@master
tar_path: gapic-maps-routes-v1-go/cloud.google.com/go/maps
tar_strip_components: 4
cache_service_account: ${{ secrets.SERVICE_ACCOUNT_CACHE }}
ignore: |
gradle/*
gradlew
gradlew.bat
```
3 changes: 3 additions & 0 deletions actions/gapic/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ inputs:
description: "Bucket name for Bazel cache"
required: false
default: gapic_action_bazel_cache
ignore:
description: "Files to keep out of staging"
required: false
dry_run:
description: "Do not push changes"
required: false
Expand Down
16 changes: 14 additions & 2 deletions actions/gapic/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,27 @@ tar xf "${TEMP_GIT_GOOGLEAPIS}/bazel-bin/${TARGET_OUTPUT}" --strip-components $I
[[ -n $(git diff "origin/master") ]] && differs_from_master=1 || differs_from_master=0

if [ $differs_from_master ]; then
set -x

git add -A

if [[ -n "${INPUT_IGNORE}" ]]; then
for f in $INPUT_IGNORE; do
git reset HEAD "${f}"
done
git status
fi

git commit -m 'feat: regenerate gapic' || true

echo "DEBUG: checking if branch already exists"
[[ -n $(git ls-remote --heads origin ${BRANCH}) ]] && has_branch=1 || has_branch=0


if [[ ( !$has_branch || -n $(git diff "origin/${BRANCH}") ) && -z $INPUT_DRY_RUN ]]; then
echo "DEBUG: if branch exists, check if different"
if [[ ($has_branch -eq 0 || -n $(git diff "origin/${BRANCH}")) && -z $INPUT_DRY_RUN ]]; then
git push -f -u origin $BRANCH

echo "DEBUG: creating pull request"
curl \
-H "Authorization: Bearer ${INPUT_GITHUB_TOKEN}" \
-H "Content-Type:application/json" \
Expand Down

0 comments on commit 11b1dca

Please sign in to comment.