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

script for .diff parsing #193

Closed
wants to merge 5 commits into from
Closed

script for .diff parsing #193

wants to merge 5 commits into from

Conversation

93Boy
Copy link
Contributor

@93Boy 93Boy commented Jul 23, 2024

Following python script fetch the content of a .diff file and parse it to extract the new package information

@nevrome
Copy link
Member

nevrome commented Jul 24, 2024

OK - looks like a good start. Now let's think about a way to integrate this with the desired workflow.

We need a GitHub Action that runs only when a PR is merged. Here's what the documentation suggests to do in this case:

on:
  pull_request:
    types:
      - closed

jobs:
  if_merged:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo The PR was merged

We want to be even more specific and only let the action run if the PR has a certain name. I think this could be be done like this:

on:
  pull_request:
    types:
      - closed

jobs:
  if_merged:
    if: |
      github.event.pull_request.merged == true &&
      github.event.pull_request.title == "[Automatic PR] Update chronicle file"
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo The PR was merged

But this is for the future. For developing I suggest to go with manual dispatch for now. That allows to manually trigger the workflow.

on:
  workflow_dispatch: # for manual dispatch

jobs:
  if_merged:
    runs-on: ubuntu-latest
    steps:
    - name: Install python and dependencies
      run: <What goes here?>
    - name: Run diff parsing script
      run: ./Parsing_new_package_diff/parse_diff.py

Because you first of all have to find a minimal (!) setup to install the necessary dependencies for your script and then run it for a URL that provides the text file with a relevant diff. For developing you can use a hardcoded one (e.g. https://patch-diff.githubusercontent.com/raw/poseidon-framework/community-archive/pull/184.diff), eventually it will probably be something like ${{ github.event.pull_request.url }}.diff.

At the beginning just let the script print its output to the console, so that you can see if it works reliably. Only in the very last step we should add the action that posts to mastodon.

@93Boy
Copy link
Contributor Author

93Boy commented Jul 24, 2024

I have updated the script in order to give a console output. Regarding triggering the action, Can we trigger it when a PR with a specific label gets merged?

@nevrome
Copy link
Member

nevrome commented Jul 24, 2024

Yes - that's exactly what I tried to explain above.
But this is not immediately relevant. For development please work with manual workflow dispatch.

@93Boy
Copy link
Contributor Author

93Boy commented Jul 24, 2024

I was thinking about the following approach . The job runs only if the PR is merged. Then sets up python and install dependencies if necessary. Afterwards Fetches the diff file from the PR URL and saves it as diff.txt and runs this python script on that
`obs:
if_merged:
if: github.event.pull_request.merged == true

  • name: Fetch PR diff
    run: |
    curl -L ${{ github.event.pull_request.diff_url }} -o diff.txt

    • name: Run parse_diff.py
      run: |
      python3 parse_diff.py < diff.txt . `

Does this look accurate?

@nevrome
Copy link
Member

nevrome commented Jul 24, 2024

The general order of events sounds correct to me. The syntax of the script is a bit off, though.

Btw. you can write multi-line code blocks in GitHub Markdown as documented here. This even supports syntax highlighting if you write the language after the first triple backticks: ```yml.

@93Boy
Copy link
Contributor Author

93Boy commented Jul 24, 2024

I have added a draft version of the yml file which fetches diff information when github.event.pull_request.merged is True. Then parse those information using the above given python script

@nevrome
Copy link
Member

nevrome commented Jul 24, 2024

OK! Does it work? If you add

on:
  workflow_dispatch:

and temporarily replace the code to construct the diff url with a hardcoded one like this

    - name: Construct diff URL
      id: construct_diff_url
      run: |
        echo "https://patch-diff.githubusercontent.com/raw/poseidon-framework/community-archive/pull/184.diff" > diff_url.txt

then you should be able to test it.

@nevrome
Copy link
Member

nevrome commented Jul 26, 2024

This PR was superseded by #194

@nevrome nevrome closed this Jul 26, 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