diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 00000000..6d6424e2 --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -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/branch-names@v7.0.7 + - 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 "github-actions@github.com" + git add -A + git commit -m '[automated commit] lint format and import sort' + git push diff --git a/.github/workflows/on-main.yml b/.github/workflows/on-main.yml index bb3b9aa4..8deaf0f5 100644 --- a/.github/workflows/on-main.yml +++ b/.github/workflows/on-main.yml @@ -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/branch-names@v7.0.7 - - 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 "github-actions@github.com" - 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 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index dab856c5..ba16460a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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/branch-names@v7.0.7 - - 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 "github-actions@github.com" - 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 }}" diff --git a/.github/workflows/up-to-date.yml b/.github/workflows/up-to-date.yml new file mode 100644 index 00000000..11b44968 --- /dev/null +++ b/.github/workflows/up-to-date.yml @@ -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 }} diff --git a/0 b/0 new file mode 100644 index 00000000..e69de29b