Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add reusable workflow for upload and download build artifacts in actions #2000

Conversation

YossiSaadi
Copy link
Contributor

@YossiSaadi YossiSaadi commented Mar 7, 2024

https://monday.monday.com/boards/3532714909/pulses/6212333840

TL;DR:

  • Call the reusable workflow of build-and-upload as first job in your workflow
  • Call the reusable action of download-builds instead the previous yarn lerna run build ... step

@shaharzil Add your storybook-blocks to the .github/workflows/build-and-upload.yml file under path.
An example usage to call the build and upload is as following:

jobs:
  build:
    name: Build
    uses: ./.github/workflows/build-and-upload.yml
    secrets:
      npm_token: ${{ secrets.npm_token }}
  ...rest of jobs (ci, build-storybook, etc.)

After this you'll have an artifact that includes all the packages/*/dist for the current workflow run id

And you need to state that the rest of the jobs cannot run in parallel, and they needs the build step to succeed. an example:

  ci:
    needs: build
    runs-on: ubuntu-latest
    ...rest of the ci job
  build-storybook:
    needs: [build, ci]
    runs-on: ubuntu-latest
    ...rest of the ci job

And instead of building inside jobs, you can now call the workflows.
Old:

steps:
  - uses: actions/checkout@v4
    with:
      fetch-depth: 0
  ...rest of steps
  - name: Run Build
    shell: bash
    run: yarn lerna run build --since=origin/master --include-dependencies
  ...rest of steps

New:

steps:
  - uses: actions/checkout@v4
    with:
      fetch-depth: 0
  ...rest of steps
  - uses: ./.github/actions/download-builds
  ...rest of steps

@YossiSaadi YossiSaadi requested a review from a team as a code owner March 7, 2024 10:59
@YossiSaadi YossiSaadi changed the title ci(build-and-upload): composite action to upload built packages to artifact ci: add reusable workflow for upload and download build artifacts in actions Mar 7, 2024
Copy link
Contributor

@shaharzil shaharzil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very very cool!

npm_token: ${{ secrets.npm_token }}
- name: Build
shell: bash
run: yarn lerna run build --since=origin/master --include-dependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is relevant only for branches that aren't master, maybe we can emphasis it somehow so no one will use it for master?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep :)
#2006 does exactly that and I will update all of our workflows once it is merged, including this new build-and-upload workflow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you wrote in the PR's description: "Call the reusable action of download-builds instead the previous yarn lerna run build ... step"
Are we cool with that happening also for the lint steps?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it is happening in like 2-3s so we're cool with it

description: Download build artifacts for all the packages and extract them to the correct location

runs:
using: "composite"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this action is composite and the second one isn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the build and upload can be a job of its own (reusable workflow)
reusable action is a step that encapsulates multiple steps
reusable workflow is a job that encapsulates multiple jobs

the reason I chose going with a reusable workflow for the build-and-upload is that in case we need the build, I'm saving the consumer from doing checkout and setup. the consumer can just do:

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

if the build-and-upload was a reusable action (composite), it would have looked like this:

  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Run Setup
        uses: ./.github/actions/setup
        with:
          npm_token: ${{secrets.npm_token}}
      - name: Run Build
        shell: bash
        run: yarn lerna run build --since=origin/master --include-dependencies

in probably 100% of the cases where consumers would need the build, they would just want it to happen, they don't need to interfere what happens with it

@YossiSaadi YossiSaadi requested a review from shaharzil March 11, 2024 12:04
@YossiSaadi YossiSaadi merged commit 05fd380 into master Mar 11, 2024
9 checks passed
@YossiSaadi YossiSaadi deleted the ci/yossi/reusable-upload-and-download-build-artifacts-workflow-and-action branch March 11, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants