Skip to content

Commit

Permalink
ci: make code-quality reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 17, 2024
1 parent 1087d96 commit 40044c0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 103 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Code Quality
on:
workflow_call:

jobs:
code-quality:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
- uses: subosito/flutter-action@v2
- name: Setup flutter
run: flutter pub get
- name: Format code
run: dart format . -l 120
- name: Apply linter auto-fixes
run: dart fix --apply
- name: Check for un-fixable issues
run: flutter analyze
- name: Run tests
run: cd example && flutter test
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
- name: Update changes in GitHub repository
if: env.modified == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
33 changes: 2 additions & 31 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,11 @@ jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
- uses: googleapis/release-please-action@v4
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
code-quality:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
- uses: subosito/flutter-action@v2
- name: Setup flutter
run: flutter pub get
- name: Lint and format
run: |
dart format . -l 120
dart fix --apply
flutter analyze
flutter test
cd example && flutter test
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
- name: Update changes in GitHub repository
if: env.modified == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add -A
git commit -m '[automated commit] lint format and import sort'
git push -f
uses: ./.github/workflows/code-quality.yml
deploy-qa-demo:
name: Deploy preview version of the storybook on firebase
needs: code-quality
Expand Down
89 changes: 17 additions & 72 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,84 +4,29 @@ on:

jobs:
up-to-date:
name: "Check branch is up to date"
uses: ./.github/workflows/up-to-date.yml

code-quality:
uses: ./.github/workflows/code-quality.yml

check-secret:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
secret-exists: ${{ steps.check.outputs.defined }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Check branch is up to date
- name: Check PR can access secrets
id: check
run: |
if git merge-base --is-ancestor ${{ github.event.pull_request.base.sha}} ${{ github.event.pull_request.head.sha}}
then
echo "Your branch is up to date."
exit 0
if [ "${{ secrets.FIREBASE_SERVICE_ACCOUNT_ZETA_DS }}" != '' ]; then
echo "defined=true" >> $GITHUB_OUTPUT;
else
echo "You need to merge / rebase."
exit 1
echo "defined=false" >> $GITHUB_OUTPUT;
fi
changes:
name: "Check for changes in code"
needs: up-to-date
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
files: ${{steps.changed-files.outputs.any_changed}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main
persist-credentials: false
- name: Get all changed *.dart, files in custom-docs or pubspec.yaml
id: changed-files
uses: tj-actions/changed-files@v41
with:
base_sha: ${{ github.event.pull_request.base.sha }}
sha: ${{ github.event.pull_request.head.sha }}
files: |
**/*.dart
custom-docs
pubspec.yaml
code-quality:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: changes
if: needs.changes.outputs.files == 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Get branch name
id: branch-name
uses: tj-actions/[email protected]
- uses: subosito/flutter-action@v2
- name: Setup flutter
run: flutter pub get
- name: Lint and format
run: |
dart format . -l 120
dart fix --apply
flutter analyze
flutter test
cd example && flutter test
- name: Check for modified files
id: git-check
run: echo "modified=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> $GITHUB_ENV
- name: Update changes in GitHub repository
if: env.modified == 'true'
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add -A
git commit -m '[automated commit] lint format and import sort'
git push
deploy-preview:
name: Deploy preview version of the storybook on firebase
needs: code-quality
needs: [up-to-date, code-quality, check-secret]
if: needs.check-secret.outputs.secret-exists == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -97,5 +42,5 @@ jobs:
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_ZETA_DS }}"
firebaseServiceAccount: "${{ env.key }}"
channelId: "pr-${{ github.event.number }}-${{ github.event.pull_request.head.ref }}"
19 changes: 19 additions & 0 deletions .github/workflows/up-to-date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Up to date
on:
workflow_call:

jobs:
up_to_date:
name: "Check branch is up to date"
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Check branch is up to date
id: check
run: exit $(gh api /repos/${{github.event.pull_request.head.repo.full_name}}/compare/${{github.event.pull_request.base.sha}}...${{github.event.pull_request.head.sha}} | jq .behind_by)
env:
GH_TOKEN: ${{ github.token }}

0 comments on commit 40044c0

Please sign in to comment.