nmfs-fish-tools / ghactions4r

Reusable github actions workflows for R packages
https://nmfs-fish-tools.github.io/ghactions4r/
12 stars 1 forks source link

Update package version in workflow #44

Closed andybeet closed 1 year ago

andybeet commented 2 years ago

Is your feature request related to a problem? Please describe.

I have a workflow that pulls data (monthly) from a website and serves it as an R data object. I dont know how to automatically version the package in a workflow. I also dont know how to add comments to the releases or add to the changelog (news.md)

Describe the solution you would like.

Within the workflow i would like to

  1. find the current version of the package and increment a minor version update.
  2. add comments in the release
  3. edit the changelog based on an R script that compares the new data pull from the old

Describe alternatives you have considered

I have found several potential actions/solutions but unsure if they are applicable since i dont fully understand

  1. GitHub automatic releases
  2. Git Semantic versioning
  3. Implement in a workflow

There are many more

Additional context

No response

k-doering-NOAA commented 2 years ago

Thanks @andybeet for suggesting this! This is exactly the sort of workflow that would be great to automate. This how I think this could be made into a github action:

Every month (using the cron trigger):

  1. Run the script that pulls data and turns it into an R object. This script could just be run in the github action most likely like it is locally currently.
  2. Increment the minor version. If this is an R package, this would just be done by making a change in the DESCRIPTION file (e.g., of doing this: https://github.com/nmfs-stock-synthesis/workflows/blob/3c615e509bf263759d02e1aa1f6f7a4cdc1680e4/.github/workflows/update-ss3-version.yml#L25)
  3. Create the release using https://github.com/marketplace/actions/automatic-releases (I think you are right that this would serve the purpose!)

A few questions:

  1. What comments and change log edits would you want to add to the release? Could they automatically generated? If not, I think releases could always be edited manually.
  2. can this script to pull the data be shared? Is the website that data is pulled from public?

I think the next steps would be to mock this up in a "sandbox" repository before adding it to yours. (e.g., I sometimes test stuff out in this minimal R pkg shell. If we come up with pieces along the way that would be helpful for other R packages, I think they can be added to ghactions4r!

Happy to talk more about this, and feel free to send me an email or video chat invite if you would like to discuss more details off of github. Either works for me!

andybeet commented 2 years ago

@k-doering-NOAA . To answer your questions:

  1. yes, i plan to create the text that would need to appear in the release notes and the news.md. I have a script i am working on to do this. The idea is that this would be part of the action and be automated
  2. Here is the current dummy repo where i am testing the workflow. It is to be used in the stocksmart repo

I'd forgotten about the DESCRIPTION file. I'll look into what you suggest.

And yes, if /when we come up with a solution together it would be great to add it to this repo for others.

k-doering-NOAA commented 2 years ago

That all sounds great - looks like you have made good progress already in the testing repo! Since everything is public, I don't think there will be any issues with permissions.

Let me know if you get stuck with a particular part and would like a second pair of eyes/some different ideas. Unfortunately, these sort of jobs are a lot of trial and error (at least for me), so it might take a bit to put together. However, I think it'll ultimately save time.

Another thought about the description file: I used sed because it didn't require installing R which takes time in the workflow, but you could also use R code to do this if you are already installing R (e.g., readLines(), grep() statements to change version, the write out the updated description file with writeLines())

An idea about the release part, if the automatic release doesn't have the right options: the Github release API could be used instead. I've used this github-script action before (e.g., this workflow to open an issue), although note that the syntax took me a while to figure out because it uses the Octokit syntax. (I think the command would be github.rest.repos.createRelease, see https://octokit.github.io/rest.js/v18#repos-create-release). There is also an R package called {gh} that could be used instead, and that uses the github API syntax. Here is an opening an issue example using the gh package as the API client . {gh} is probably a good option if you are already installing R in the workflow! One other note is that you may need to create a secret token different than the github_token and add it in the workflow if the workflow posts any API calls to a repo that it is not run in - I don't think this is the case for you, but thought I mention since it took me forever to figure this out last week!

k-doering-NOAA commented 2 years ago

@andybeet, how are things going with this?

andybeet commented 1 year ago

@k-doering-NOAA So i have reached a point where i am somewhat happy with the workflow. There are still some manual steps but i am ok with that for now. The final workflow:

GitHub action to:

Then when the email is received, if the report contains changes to the data (most weeks it will not, i hope!!) then i manually:

For now this works, let's see how long i can stomach this

Here is the repo: https://noaa-edab.github.io/stocksmart/

k-doering-NOAA commented 1 year ago

Thanks, Andy! That seems like you were able to automate a large part of your workflow, which is great! I'm going to close this, but if you think there is anything in the custom workflow you created that should be migrated into ghactions4r for others to use, feel free to reopen and I would to work with you to get it into the package.