Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Artifact Passing from Automate-Metrics to Build-Book #415

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

Merged
merged 31 commits into from
Mar 25, 2024

Conversation

jukent
Copy link
Contributor

@jukent jukent commented Mar 20, 2024

Editing this for conciseness for new readers:

This PR removes automatic metrics from trigger-preview and nightly-build. The metrics are only calculated in publish-book.yaml, which now happens weekly. We can have a wider conversation about the ideal relationship of each action.

Some changes were made to Cookbooks-action build-book.yaml (merged in other PRs) to update the infrastructure to handle the artifact passing in this case.


This PR attempts to check out the results of the directory after the automate-metrics step to be passed into the book-build action. Currently the repo is re-checked out and all liminal files are lost, resulting in no metrics on the website.

It looks like the book-build in Cookbook-actions already handles the logic for when an artifact is passed in:

    steps:
      - name: Checkout the code from the repo
        if: inputs.build_from_code_artifact == 'false'
        uses: actions/checkout@v4

      #  The next two steps should replicated checking out the code
      - name: Download code artifact
        id: get_code_artifact
        if: inputs.build_from_code_artifact == 'true'
        uses: dawidd6/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          workflow: trigger-book-build.yaml
          run_id: ${{ github.event.workflow_run.id }}
          name: ${{ inputs.code_artifact_name }}

      - name: Unzip the code
        if: inputs.build_from_code_artifact == 'true'
        run: |
          unzip pr_code.zip
          rm -f pr_code.zip  

So this simply uploads the artifact and then grabs it later.

Related to #319

Copy link
Contributor

github-actions bot commented Mar 20, 2024

👋 Thanks for opening this PR! The Cookbook will be automatically built with GitHub Actions. To see the status of your deployment, click below.
🔍 Git commit SHA: 5c468c4
✅ Deployment Preview URL: https://projectpythia.github.io/_preview/415

@erogluorhan
Copy link
Member

erogluorhan commented Mar 20, 2024

While I was checking this PR's files, I started to think that as a result of the recent automate metrics PRs, we made nightly-build.yaml and publish-site.yaml actions look and work very similar to each other, and we dropped the use cases where we might want to see effects of some implementations in the nightly builds without actually deploying them (e.g. how I did with the theme update recently). That said how about:

  • Revert the recent changes we made to the nightly-build as part of the metric automation work (i.e. remove the automate metrics and deploy the site jobs)
  • Instead add a nightly or weekly cron job into the publish-site.yaml so that the website can still be deployed automatically nightly/weekly (in addition to pushes to main and workflow-dispatch) with automated metrics

@jukent
Copy link
Contributor Author

jukent commented Mar 20, 2024

While I was checking this PR's files, I started to think that as a result of the recent automate metrics PRs, we made nightly-build.yaml and publish-site.yaml actions look and work very similar to each other, and we dropped the use cases where we might want to see effects of some implementations in the nightly builds without actually deploying them (e.g. how I did with the theme update recently). That said how about:

  • Revert the recent changes we made to the nightly-build as part of the metric automation work (i.e. remove the automate metrics and deploy the site jobs)
  • Instead add a nightly or weekly cron job into the publish-site.yaml so that the website can still be deployed automatically nightly/weekly (in addition to pushes to main and workflow-dispatch) with automated metrics

Thanks for the idea Orhan. It's good to know that there were use-cases for wanting to run the nightly build without deployment. I think the need for a nightly build is solved by running the publish-site weekly (and with fresh metrics). This PR now represents that.

find-pull-request:
needs: automate-metrics
Copy link
Member

Choose a reason for hiding this comment

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

I am hesitant about this removal, i.e. I think keeping the "automate-metrics" job in the "trigger-preview.yaml" workflow would still be valuable to see how the Metrics page would render in the preview of any PR. This is because right after any PR is merged into main, there will be a publish-site workflow run, which will update the metrics on the website.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I was confused about each action a bit. I agree and will re-introduce this - but my attempts at introducing an artifact have broken the actions on my branch.

I think it might be better for me to focus on getting one action working (the publish-site), and then the knowledge I gain should transfer to setting up the trigger-preview to use automate-metrics again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay I added this back for now, but I know it won't work yet and I'm not sure if it can work.

I think this because the trigger-preview is grabbing a book-build artifact.
artifact_name: book-zip-${{ needs.find-pull-request.outputs.number }} that is zipped from the trigger-site-build action (which is triggered by a PR and thus does not have access to the secrets necessary to run the metrics collection). And in turn the trigger-preview is triggered by the trigger-site-build.

There seems to be a possible work around with trigger-preview being allowed to access secrets, so we could rebuild the book in that step, but that seems computationally expensive. I have to think about this more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed again per our discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if there is a benefit to moving the automate-metrics step to Cookbook-Actions even though we don't intend for it to be re-usable across repositories. It seems that if it existed as a re-usable workflow there are different permissions. For example, it could access secrets that live in the Cookbook-Actions repo and be triggered by a PR in the portal, zip up it's artifact and pass that back to the trigger-preview workflow. It would be a bit of an overall, and would be the next step after the artifact passing is functioning and well understood.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can revisit this in the future?

@jukent
Copy link
Contributor Author

jukent commented Mar 21, 2024

YAML file is no longer malformed, and actions are running but failing at the build step during the downloading of the artifact.

Not Found - https://docs.github.com/rest/actions/workflow-runs#list-workflow-runs-for-a-workflow

There is a successful uploading of the artifact, but I'm not sure if I'm missing a critical zip step like this from the build-book action

      - name: Zip the book
        run: |
          set -x
          set -e
          if [ -f book.zip ]; then
              rm -rf book.zip
          fi
          zip -r book.zip ${{ inputs.path_to_notebooks }}/ ${{ inputs.output_path }}

@jukent
Copy link
Contributor Author

jukent commented Mar 21, 2024

One thing I'm noticing is that within the Cookbook-Actions book-build.yaml, if there is an artifact it runs like so:

      #  The next two steps should replicated checking out the code
      - name: Download code artifact
        id: get_code_artifact
        if: inputs.build_from_code_artifact == 'true'
        uses: dawidd6/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          workflow: trigger-book-build.yaml
          run_id: ${{ github.event.workflow_run.id }}
          name: ${{ inputs.code_artifact_name }}

I think the action is failing on my fork because of workflow: trigger-book-build.yaml. There is not a trigger-book-build.yaml file on the Portal, so I am going to try to add one - but I'm a little confused about how it looks.

In the Foundations repo and all of the Cookbooks it looks like so:

name: trigger-book-build
on:
  pull_request:

jobs:
  build:
    uses: ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml@main
    with:
      environment_name: pythia-book-dev
      artifact_name: book-zip-${{ github.event.number }}
      # Other input options are possible, see ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml

This seems to work for Foundations and the Cookbooks, so editing build-book.yaml could break important things -- but I have to ask: Is this artifact call if-check being used anywhere? or tested?

It seems to me like this workflow would start the build-book.yaml from the top all over again. I'd edit it to include a code_artifact_name input (artifact_name points to where the book should be zipped, not where the zipped input is) and be triggered by a workflow_call instead of a PR. Still this new file will mostly be a place holder while I figure out what we want to do.

@jukent jukent reopened this Mar 21, 2024
@jukent
Copy link
Contributor Author

jukent commented Mar 21, 2024

Thanks @brian-rose for explaining that it the workflow: trigger-book-build.yaml in Cookbook Actions build-book.yaml doesn't trigger the trigger-book-build.yaml workflow, but tells the book-build action to look in that action for the artifact.

I opened up a PR ProjectPythia/cookbook-actions#104 that changes the trigger workflow to be an input with the previous default, that way we should be able to set it to publish-site.yaml in this workflow. I commented it out for now (because that input doesn't exist yet it stops the whole action from attempting to run with a YAML error)

@jukent
Copy link
Contributor Author

jukent commented Mar 25, 2024

Caught a typo in my Cookbook-actions update. I'm pretty sure that the trigger_workflow input should just be publish-book.yaml - but it could also need the full path .github/workflows/publish-book.yaml.

If I don't have success with either of those two - there seems to be way I could set the workflow to blank, and workflow_search to true. There are some options from the download-artifact documentation

@jukent
Copy link
Contributor Author

jukent commented Mar 25, 2024

Artifact passing is working on my branch! https://github.com/jukent/projectpythia.github.io/actions/runs/8425450722

@jukent jukent marked this pull request as ready for review March 25, 2024 20:32
@jukent jukent requested a review from a team as a code owner March 25, 2024 20:32
@jukent jukent requested review from erogluorhan and removed request for a team March 25, 2024 20:33
Copy link
Member

@erogluorhan erogluorhan left a comment

Choose a reason for hiding this comment

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

I'll approve this after a quick type is fixed

find-pull-request:
needs: automate-metrics
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can revisit this in the future?

Co-authored-by: Orhan Eroglu <[email protected]>
@jukent jukent requested a review from erogluorhan March 25, 2024 20:41
@jukent jukent merged commit 367d802 into ProjectPythia:main Mar 25, 2024
github-actions bot pushed a commit that referenced this pull request Mar 25, 2024
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