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

[BUG] Fix openapi.json generation workflow #891

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peytondmurray
Copy link
Contributor

@peytondmurray peytondmurray commented Sep 26, 2024

Fixes #888.

Description

Apparently github.event.pull_request.head.ref isn't always guaranteed to exist on pull requests. The docs for EndBug/add-and-commit suggest using this ref because otherwise the branch is checked out in a detached head state. A simple search for "how to add and commit in github actions" turns up a bunch of results that suggest that in fact you can just call actions/checkout and then git add .; git commit -m <message>; git push, so I'm not really sure who is right. The PR tests out the second approach.

Pull request checklist

  • Did you test this change locally?
  • Did you update the documentation (if required)?
  • Did you add/update relevant tests for this change (if required)?

Update

This PR doesn't actually trigger the workflow that updates openapi.json, but I've been trying it on #881:

  1. Checking out with the github.event.pull_request.head.ref, which doesn't exist sometimes:
      - name: "Checkout repository 🛎️"
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.ref }}
  1. Not checking out specific ref:
        with:
          ref: ${{ github.event.pull_request.head.ref }}
  1. Checking out with fetch-depth: 0:
        with:
          ref: ${{ github.event.pull_request.head.ref }}
          fetch-depth: 0
  1. Checking out without a specific ref and with fetch-depth: 0:
        with:
          fetch-depth: 0
  1. Checking out with github.head_ref:
        with:
          ref: ${{ github.head_ref }}
  1. Checking out with fetch-depth: 0:
        with:
          ref: ${{ github.head_ref }}
          fetch-depth: 0

It seems like this might not be possible according to this community discussion, or it should be possible according to this, this, this, and this, but it's unclear if these work on PRs coming from forks. This suggests that I need to use a personal access token rather than the GITHUB_TOKEN generated during workflows, but would be suboptimal because we'd have to switch it out if whoever owns it eventually moves on from conda-store development. I thought about trying to do what pre-commit.ci does, but it's quite convoluted: its entrypoint is a js module which spawns a python subprocess (??) which clones and then copies your branch, then does a cherry-pick (???) to get the formatted changes in. This approach checks out correctly if I replace github.event.issue.number with github.event.pull_request.number, but then fails with a permissions error despite using secrets.GITHUB_TOKEN with the permissions set to

permissions:
  contents: write
  pull-requests: write

in the commit/push step.

Copy link

netlify bot commented Sep 26, 2024

Deploy Preview for conda-store canceled.

Name Link
🔨 Latest commit 00c58f5
🔍 Latest deploy log https://app.netlify.com/sites/conda-store/deploys/66f4fc48d69f90000861142b

@peytondmurray peytondmurray marked this pull request as draft September 26, 2024 23:38
@peytondmurray peytondmurray changed the title [BUG] Manually commit changes to API docs in CI [BUG] Fix openapi.json generation workflow Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New 🚦
Development

Successfully merging this pull request may close these issues.

[BUG] - Generate openapi.json github action is flaky
1 participant