Skip to content

Commit

Permalink
ci: only run workflows in case build step has succeeded and shown c…
Browse files Browse the repository at this point in the history
…hanges one of the monorepo packages
  • Loading branch information
YossiSaadi committed Mar 12, 2024
1 parent afa2d01 commit 20c7868
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ on:
secrets:
npm_token:
required: true
outputs:
has_changes:
description: Whether there are any changes in the monorepo.
value: ${{ jobs.build-and-upload.outputs.has_changes }}

jobs:
build-and-upload:
name: Build and Upload
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.check-changed-packages.outputs.has_changes }}

steps:
- uses: actions/checkout@v4
with:
Expand All @@ -17,14 +25,19 @@ jobs:
uses: ./.github/actions/setup
with:
npm_token: ${{ secrets.npm_token }}
- id: check-changed-packages
uses: ./.github/actions/check-changed-packages
- id: determine-since-flag
if: ${{ steps.check-changed-packages.outputs.has_changes == 'true' }}
uses: ./.github/actions/determine-lerna-since-flag
- name: Build
if: ${{ steps.check-changed-packages.outputs.has_changes == 'true' }}
shell: bash
env:
SINCE_FLAG: ${{ steps.determine-since-flag.outputs.since_flag }}
run: yarn lerna run build $SINCE_FLAG --include-dependencies
- name: Upload
if: ${{ steps.check-changed-packages.outputs.has_changes == 'true' }}
uses: actions/upload-artifact@v4
with:
name: ci-builds-${{ github.run_id }}-${{ github.run_attempt }}
Expand Down
24 changes: 11 additions & 13 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
name: "Chromatic"
name: Chromatic

on: push

jobs:
chromatic-deployment:
build:
name: Build
uses: ./.github/workflows/build-and-upload.yml
secrets:
npm_token: ${{ secrets.npm_token }}

publish-chromatic:
name: Publish Chromatic
needs: build
if: ${{ needs.build.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -13,18 +22,7 @@ jobs:
uses: ./.github/actions/setup
with:
npm_token: ${{ secrets.npm_token }}
- id: check-changed-packages
uses: ./.github/actions/check-changed-packages
- id: determine-since-flag
uses: ./.github/actions/determine-lerna-since-flag
- name: Run Build
if: ${{ steps.check-changed-packages.outputs.has_changes == 'true' }}
shell: bash
env:
SINCE_FLAG: ${{ steps.determine-since-flag.outputs.since_flag }}
run: yarn lerna run build $SINCE_FLAG --include-filtered-dependencies
- name: Publish to Chromatic
if: ${{ steps.check-changed-packages.outputs.has_changes == 'true' }}
uses: chromaui/action@v11
with:
token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ jobs:
secrets:
npm_token: ${{ secrets.npm_token }}

pr_checks:
test:
name: Test
needs: build
if: ${{ needs.build.outputs.has_changes == 'true' }}
uses: ./.github/workflows/test.yml
secrets:
npm_token: ${{ secrets.npm_token }}
18 changes: 11 additions & 7 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ on:
- "master"

jobs:
prerelease:
build:
name: Build
if: "contains(github.event.head_commit.message, '[prerelease]')"
uses: ./.github/workflows/build-and-upload.yml
secrets:
npm_token: ${{ secrets.npm_token }}

prerelease:
name: Prerelease
needs: build
if: ${{ needs.build.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -18,12 +27,7 @@ jobs:
with:
npm_token: ${{ secrets.npm_token }}
- uses: ./.github/actions/git-creds
- name: Check if there are changed packages
run: |
changed_packages=$(yarn -s lerna ls --since=origin/master --json --loglevel=error)
[[ $changed_packages = "[]" ]] && echo "Skipping prerelease. Nothing to prerelease as Lerna didn't detect any changes." && exit 1 || echo "Changed detected. Continuing to prerelease" && echo "$changed_packages"
- name: Build all affected packages
run: yarn lerna run build --since=origin/master --include-dependencies
- uses: ./.github/actions/download-builds
- name: Generate new versions
id: generate-versions
run: |
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ jobs:
secrets:
npm_token: ${{ secrets.npm_token }}

prerequisites:
test:
name: Test
needs: build
if: ${{ needs.build.outputs.has_changes == 'true' }}
uses: ./.github/workflows/test.yml
secrets:
npm_token: ${{ secrets.npm_token }}

release:
needs: [build, prerequisites]
name: Release
needs: [build, test]
if: ${{ needs.build.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Notice that for this workflow to run properly, you need to first run the build-and-upload workflow.
# This is because the test workflow depends on the build-and-upload workflow to download the builds from a previous job in the same workflow run.

name: Test & Lint

on:
Expand Down

0 comments on commit 20c7868

Please sign in to comment.