-
-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
package: | ||
required: true | ||
type: string | ||
sdk: | ||
required: false | ||
type: string | ||
default: dart | ||
|
||
jobs: | ||
cancel-previous-workflow: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 # pin@0.11.0 | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
format-and-fix: | ||
name: Format & fix code | ||
if: ${{ !startsWith(github.ref, 'refs/heads/release/') }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 20 | ||
defaults: | ||
run: | ||
working-directory: ${{ inputs.package }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d # pin@v1 | ||
if: ${{ inputs.sdk == 'dart' }} | ||
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # pin@v2.10.0 | ||
if: ${{ inputs.sdk == 'flutter' }} | ||
|
||
- run: ${{ inputs.sdk }} pub get | ||
|
||
- run: dart format . | ||
|
||
- run: dart fix --apply | ||
|
||
# actions/checkout fetches only a single commit in a detached HEAD state. Therefore | ||
# we need to pass the current branch, otherwise we can't commit the changes. | ||
# GITHUB_HEAD_REF is the name of the head branch. GitHub Actions only sets this for PRs. | ||
- run: ../scripts/commit-formatted-code.sh $GITHUB_HEAD_REF | ||
if: env.GITHUB_HEAD_REF != null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
GITHUB_BRANCH="${1}" | ||
|
||
if [[ $(git status) == *"nothing to commit"* ]]; then | ||
echo "Nothing to commit. All code formatted correctly." | ||
else | ||
echo "Formatted some code. Going to push the changes." | ||
git config --global user.name 'Sentry Github Bot' | ||
git config --global user.email 'bot+github-bot@sentry.io' | ||
git fetch | ||
git checkout ${GITHUB_BRANCH} | ||
git commit -am "Format & fix code" | ||
git push --set-upstream origin ${GITHUB_BRANCH} | ||
fi |