Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: make code-quality reusable
Browse files Browse the repository at this point in the history
thelukewalton committed Jun 12, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 9eb777b commit 0c3e30f
Showing 5 changed files with 88 additions and 101 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
32 changes: 2 additions & 30 deletions .github/workflows/on-main.yml
Original file line number Diff line number Diff line change
@@ -12,39 +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
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
88 changes: 17 additions & 71 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -4,83 +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
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
@@ -96,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 }}"
31 changes: 31 additions & 0 deletions .github/workflows/up-to-date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Up to date
on:
workflow_call:
outputs:
is_up_to_date:
description: "If the branch is up to date"
value: ${{ jobs.up_to_date.outputs.output1 }}
jobs:
up_to_date:
name: "Check branch is up to date"
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
is_up_to_date: ${{ steps.check.outputs.is_up_to_date }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
- name: Check branch is up to date
id: check
run: |
behind=$(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)
if (( $behind == 0 )); then
echo "is_up_to_date=true" >> $GITHUB_OUTPUT
else
echo "is_up_to_date=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ github.token }}
- run: echo ${{ steps.check.outputs.is_up_to_date }}
Empty file added 0
Empty file.

0 comments on commit 0c3e30f

Please sign in to comment.