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

New custom-logic action input #68

Closed
wants to merge 1 commit into from

Conversation

aciceri
Copy link

@aciceri aciceri commented Mar 9, 2023

Description

I've added a new option custom-logic that allows executing custom logic after that update-flake-lock.sh is executed but before that the PR body is interpolated. The use case that justified this is that I wanted to put the output of nix store diff-closures inside the PR body. But I couldn't do this before the entire update-flake-lock action since I needed to run it after that the lockfile was updated.

 - name: Update flake.lock
    uses: aciceri/update-flake-lock@main
    with:
      custom-logic: |
        EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
        echo "DIFF_CLOSURES<<$EOF" >> $GITHUB_ENV
        nix run .#diff-closures >> $GITHUB_ENV
        echo "$EOF" >> $GITHUB_ENV
      pr-title: "Automatic `flake.lock` update"
      pr-body: |
        # Automatic update
        ## Inputs updated
        ```
          {{ env.GIT_COMMIT_MESSAGE }}
        ```
        ## Closures diff
        ```
        {{ env.DIFF_CLOSURES }}
        ```

image

Frankly I don't know if you want this, perhaps it's just an useless complication that will be useful for a small portion of people. Meanwhile I leave it here as a draft PR and only if you like it I'll add some lines in the README

Checklist
  • Tested functionality against a test repository (see "How to test changes") Not the template one but this
  • Added or updated relevant documentation (leave unchecked if not applicable)

@aciceri aciceri marked this pull request as draft March 10, 2023 00:06
@grahamc
Copy link
Member

grahamc commented Apr 11, 2023

Hi @aciceri, we've been discussing this issue internally and think it would be better solved by documentation about how to accomplish this, instead of building support for it in directly. We think that would ultimately better and more flexible for folks. Does that make sense to you?

@aciceri
Copy link
Author

aciceri commented Apr 11, 2023

@grahamc am I missing something or this isn't accomplishable by using the action as is? At the beginning I've tried looking for a workaround that didn't require me to fork the action but I couldn't (can't remember details but my ideas were really ugly/convoluted, it was easier just rewriting the action). I remind you that I want to execute my custom logic before the PR is created/updated but after that the commit with the updated inputs is created.

@cole-h
Copy link
Member

cole-h commented Apr 11, 2023

Correct, using only this action in its current state, it is not possible to do what you want.

However, is there a reason why executing the custom logic after the PR is created/updated is unacceptable? I think it would be fairly simple to edit the PR description immediately after it has been submitted, and we could add an example in the README demonstrating that.

Specifically, the create-pull-request action we use exposes the PR number of the created PR (as well as whether the operation that action took), and we re-expose that information. So I can imagine that it would be possible to utilize that with another GitHub Action that accepts a PR number or some other identifying information and change the PR body using that info.

@cole-h
Copy link
Member

cole-h commented Apr 11, 2023

I did a bit of looking and found a couple actions that might be useful:


Another solution could be to use gh CLI in the action like this:

pr=68 # give the update-flake-lock step an id and use ${{ steps.<ID>.outputs.pull-request-number }} here
gh pr view "$pr" --json body --jq .body > body

cat >> body <<EOF

---

Here is some more stuff that I would like to add
EOF

gh pr edit "$pr" --body-file ./body
rm ./body

or this:

pr=68 # give the update-flake-lock step an id and use ${{ steps.<ID>.outputs.pull-request-number }} here
gh pr view "$pr" --json body --template \
'{{.body}}

---

Here is some more stuff that I would like to add' > body

gh pr edit "$pr" --body-file ./body
rm ./body

@aciceri
Copy link
Author

aciceri commented Apr 11, 2023

Uh you are right, I couldn't think the simplest solution. The only difference is that this way there will be a time delta where the PR is created but I don't have a complete text body for it (in my case it takes about 40 minutes to build a new Emacs) but this isn't a problem for my use case.

Said this I think you can close this, or, if you prefer, I can change this adding an example doing what you suggest (I believe that having diffs or other tasks like running vulnix could be in the general interest for nix folks).

Thanks :)

@grahamc
Copy link
Member

grahamc commented Apr 12, 2023

I'm going to close this PR since it is pretty directionally different. If you're up for it, it'd be awesome for you to submit an example to the README. Thanks, @aciceri!

@grahamc grahamc closed this Apr 12, 2023
detsys-pr-bot pushed a commit to detsys-pr-bot/update-flake-lock that referenced this pull request Nov 20, 2024
…m DeterminateSystems/update-deps` (`3b8b6d7f42f7ad467dd6f769913ac162731507c6`)
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.

3 participants