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

mkhtml: Generate local JSON file with core modules and their last commit #2140

Merged
merged 18 commits into from Apr 14, 2022

Conversation

tmszi
Copy link
Member

@tmszi tmszi commented Jan 29, 2022

In the context of creating and using a core_modules_with_last_commit.json file after creating and submitting a new release tag to remote repository e.g. git tag -a 8.2.0 -m "Release 8.2.0" and git push origin 8.2.0 a new draft is automatically created with GitHub action workflow "Create new release draft" #2224 with attached two files core_modules_with_last_commit.json and core_modules_with_last_commit.patch.

JSON file data structure:

"r.pack": {
    "commit": "547ff44e6aecfb4c9cbf6a4717fc14e521bec0be",
    "date": "2022-02-03T11:10:06+01:00"
},

During compilation source code without .git dir, this local file "core_modules_with_last_commit.json" is used instead of getting Git commits from remote GitHub API server.

@tmszi tmszi added the bug Something isn't working label Jan 29, 2022
@wenzeslaus wenzeslaus added this to the 8.2.0 milestone Jan 29, 2022
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

I need to look at this more, but it seems that something like this is the only way to get all the info from Git. I assume others already looked into bending Git to be more like Subversion and that didn't work. I would still ask though, why is carrying this generated file in the code necessary?

As for the implementation, the automatic commit won't work well here as far as I can tell. Doing on the PR branch will record wrong commit hashes. Doing it on the main branch will result in doubling the amount of commits as every commit (merge) will require another commit as an update for this file. (And also disabling some of the mandatory checks may be needed to make it work.)

I came up with two scenarios which could work:

  1. Make the workflow a dispatch workflow (or whatever these are called) so that it is called manually. Part of the release procedure would be to trigger this workflow, it would create a PR against the release branch (or commit, but PR sounds safer!). This is closer to your current proposal, than the other option.
  2. Make the generated file a GitHub Actions artifact (possible for all commits on all branches) and let people download it from GitHub when needed or, for convenience, upload it somewhere from GitHub actions (using scp or FTP). This could be part of creating the release tarball. Requires more manual work, but doesn't require to have the generated file in the source code.

@tmszi tmszi force-pushed the generate-local-pgms-json-file-with-last-commit branch from a768d3c to 29a7e7c Compare January 30, 2022 06:14
@tmszi
Copy link
Member Author

tmszi commented Jan 30, 2022

As for the implementation, the automatic commit won't work well here as far as I can tell. Doing on the PR branch will record wrong commit hashes. Doing it on the main branch will result in doubling the amount of commits as every commit (merge) will require another commit as an update for this file. (And also disabling some of the mandatory checks may be needed to make it work.)

Auto commit has some limitation but in our case Git repository allow Squash and Merge and if this GitHub action is allowed on the only main branch, it is work as expected (update this JSON file is triggered on push to main branch and one auto commit is pushed). I tested it on my test repository and it worked as expected.

@tmszi tmszi mentioned this pull request Feb 11, 2022
@lucadelu
Copy link
Contributor

Tested with 7.8.7 release branch and it work properly

--------------------------------------------------
Started compilation: Fri Feb 11 09:20:13 UTC 2022
--
Errors in:
No errors detected.
--
Finished compilation: Fri Feb 11 09:29:52 UTC 2022

@tmszi
Copy link
Member Author

tmszi commented Feb 12, 2022

I need to look at this more, but it seems that something like this is the only way to get all the info from Git. I assume others already looked into bending Git to be more like Subversion and that didn't work. I would still ask though, why is carrying this generated file in the code necessary?

Yes you are right it is not necessary.

  1. Make the generated file a GitHub Actions artifact (possible for all commits on all branches) and let people download it from GitHub when needed or, for convenience, upload it somewhere from GitHub actions (using scp or FTP). This could be part of creating the release tarball. Requires more manual work, but doesn't require to have the generated file in the source code.

I decided to implement this procedure. The resulting GitHub workflow pgms-with-last-commit-patch-file artifact will create a pgms_with_last_commit.patch (new pgms_with_last_commit.json file) that will be downloadable as zip file for the GRASS GIS GNU/Linux distribution maintainer and applicable as a patch in its package build process.

@tmszi
Copy link
Member Author

tmszi commented Feb 13, 2022

@neteler, I think we should include this PR in the next release 8.0.1 and 7.8.7 and solve GitHub REST API rate limit completely (which means every core module manual page will have commit and commit date, when GRASS GIS is compile from release archive which doesn't have Git).

The generated pgms_with_last_commit.json file can then be downloaded from the GitHub action workflow pgms-with-last-commit-patch-file artifact (for branch) and pasted into the release archive during creation.

…mmit

For every pushed commit GitHub Generate PGMS last commit JSON file
action worflow update "pgms_with_last_commit.json" file (auto commit),
which contains all PGMS (core modules) with last commit.

JSON file data structure:

{"pgm": {"commit": "git log -1 PGM src dir"}, ...}

During compilation source code without .git dir, this local file
"pgms_with_last_commit.json" is used instead of getting Git commit
from remote GitHub API server.
…mmit

For every pushed commit GitHub 'Generate PGMS last commit JSON file
action worflow artifact' create "pgms_with_last_commit.patch" patch file,
which contains all PGMS (core modules) with last commit. Which is
donwloadable from GitHub actions workflows page as
pgms-with-last-commit-patch-file.zip file.

JSON file data structure:

{"pgm": {"commit": "git log -1 PGM src dir"}, ...}

During compilation source code without .git dir, this local file
"pgms_with_last_commit.json" is used instead of getting Git commit
from remote GitHub API server.
@neteler
Copy link
Member

neteler commented Feb 13, 2022

I think we should include this PR in the next release 8.0.1 and 7.8.7 and solve GitHub REST API rate limit completely

Thanks for your work on this PR! I am a bit undecided if 8.0.1 and 7.8.7 or better 8.0.2 and 7.8.8? If the former, then we will need a longer test phase (I just published 8.0.1RC1 yesterday, see grass-dev mailing list). I suggest to discuss it on grass-dev to reach more people.

…mmit

For every pushed commit GitHub Generate PGMs last commit JSON file
action worflow generate "pgms_with_last_commit.json" file
(pgms-with-last-commit-patch-file artifact that will be downloadable
as zip file), which contains all PGMs (core modules) with last commit.

JSON file data structure:

{"PGM": {"commit": "git log -1 PGM src dir"}, ...}

During compilation source code without .git dir, this local file
"pgms_with_last_commit.json" is used instead of getting Git commit
from remote GitHub API REST server.
@tmszi tmszi force-pushed the generate-local-pgms-json-file-with-last-commit branch from 718c945 to fc46089 Compare February 13, 2022 13:07
@lucadelu
Copy link
Contributor

I would prefer 7.8.7 and 8.0.1

@wenzeslaus
Copy link
Member

I prefer after 7.8.7 and 8.0.1 or later. This is not even reviewed, while 8.0.1 is ready to go.

Let's not backport large or invasive changes and let's not backport quickly or right before a release. As far as I'm concerned, this can sit on the main branch all the way to 8.2.0. Date in a man page is not important enough to risk breaking compilation on a release branch.

@tmszi
Copy link
Member Author

tmszi commented Feb 14, 2022

Date in a man page is not important enough to risk breaking compilation on a release branch.

I will try to explain in more detail what other consequences the exceeded GitHub REST API rate limit has during compilation, which is reported in the issue #2186, and that is why I suggest integrating it into 8.0.1 and 7.8.7 as soon as possible after thorough testing:

  1. Compilation GRASS GIS from source code without Git was successfull on computer which never has installed GRASS GIS before (.grass8 dir doesn't exists)
  2. GitHub REST API rate limit was exceeded during compilation
  3. After GRASS GIS installation you want install some new addon: g.extension i.sentinel
  4. You get error message GitHub REST API rate limit was exceeded, and user must wait (1 hour). Information when rate limit is freed is not included, and this is reason why I created PR scripts/g.extension: make GitHub REST API server rate limit error message more verbose #2193
GRASS nc_basic_spm_grass7/PERMANENT:~ > g.extension i.sentinel
ERROR: The download of the JSON file with add-ons paths from the GitHub
       REST API server wasn't successful, rate limit exceeded, 60 requests
       per hour per your computer IP address. The previous downloaded JSON
       file will not be used, because does not exists. You can try it again
       on Saturday Feb 12 14:57:22 2022.
  1. Non technical user don't understand what is GitHub REST API rate limit without better explanation.

As already mentioned, the main problem is that we are depend on proprietary GitHub REST API (g.extension module) which has limitation and who has control over us, not we over him.

Let's not backport large or invasive changes and let's not backport quickly or right before a release.

It is just a sugestion that explains in much more detail why it will be good to implement these changes as soon as possible.

Code changes with this PR:

  1. New GitHub action workflow artifact, which I tested separately on my test repository
  2. Simple new script which generate new JSON file
  3. Open and read JSON file

Code changes with PR #2193:

  1. Changed error message string

@ninsbl
Copy link
Member

ninsbl commented Feb 14, 2022

Please see my comments on #2193
We should make sure that compilation and installation of addons works in 7.8.7 and 8.0.1.
If merging this PR is required for that I would agree to merge. However, it seems that a workaround for the related compilation bug is in place in 7.8.7 and 8.0.1, so from that point of view I agree with @wenzeslaus that we rather test this more broadly in the development version and include the more elegant and accurate handling of dates manuals in 8.2.

Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

OK. I invstigated the possibility to deploy to a gist to circumvent the API (content could be downloaded as raw file directly), but only users seem to be able to own gists (not organizations (here osgeo) and repos (grass)...
So, I guess artifacts are the best option if we do not publish the JSON file other places (which would have other drawbacks).
Another question is if we could find a mechanism where the JSON file is attempted to be downloaded only once (i.e. at start of compilation) or if it has been updated since the last download or lder than e.g one hour.

That said, this PR definately improves the current situation.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

This seems like a step in the right direction if we want to harvest all the information from Git.

If I remember correctly, GitHub artifacts don't have predictable URLs. Any plans for that? We could upload somewhere from GitHub Actions using something like FTP/SCP and secrets.

I would like to see this running on PRs as well for testing purposes, esp., for cases when you make change here. The additional_checks.yml workflow/job is meant for random things like this, so you could add the generator script there with some check of the JSON content.

.github/workflows/gen_pgms_last_commit_json_file.yml Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated
commit[0]["commit"]["author"]["date"],
"%Y-%m-%dT%H:%M:%SZ",
).strftime(datetime_format)
if gs:
Copy link
Member

Choose a reason for hiding this comment

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

The whole "can't import grass.script therefore I'm compiling" is shaky, but perhaps good enough for this PR.

utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/gen_pgms_last_commit.py Outdated Show resolved Hide resolved
utils/gen_pgms_last_commit.py Outdated Show resolved Hide resolved
utils/gen_pgms_last_commit.py Outdated Show resolved Hide resolved
.github/workflows/gen_pgms_last_commit_json_file.yml Outdated Show resolved Hide resolved
.github/workflows/gen_pgms_last_commit_json_file.yml Outdated Show resolved Hide resolved
@wenzeslaus
Copy link
Member

...As already mentioned, the main problem is that we are depend on proprietary GitHub REST API (g.extension module) which has limitation and who has control over us, not we over him.

Right, I think everyone agrees with that. My point is that there is no reason to have anything like that in the source code in the first place when it brings no benefit and since the code as is doesn't work, we can just drop it and, in some cases, live with some missing metadata in manual pages for 7.8 and 8.0. For 8.2, we can see how this PR works.

@tmszi
Copy link
Member Author

tmszi commented Feb 17, 2022

If I remember correctly, GitHub artifacts don't have predictable URLs. Any plans for that? We could upload somewhere from GitHub Actions using something like FTP/SCP and secrets.

I assumed that this one manual step would be enough. When we want make new release (source code without Git), person which make this release via GitHub page, first download pgms_with_last_commit.json file from last GitHub workflow pgms-with-last-commit-patch-file artifact to him computer and than upload as attach into process of making GitHub GRASS GIS release. File will be part of archive e.g. https://github.com/OSGeo/grass/archive/refs/tags/8.0.1RC1.tar.gz.

@wenzeslaus
Copy link
Member

....we want make new release (source code without Git)...first download pgms_with_last_commit.json file from last GitHub workflow...than upload as attach into process...

The release procedure is already a lot of work. We should be working towards minimizing the steps and automating ideally everything.

...file will be part of archive...

The GitHub page says you can include binary files...in the binaries box. I don' see anything about combining that with the tarball.

However, the download links in a release are stable and it seems you can upload to release from GitHub actions (softprops/action-gh-release, svenstaro/upload-release-action, JasonEtco/upload-to-release, ...).

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

The release draft action is a great improvement. I'm not sure about the actions/create-release part since it is kind of buried in the context of this PR. The actions/upload-release-asset is more clear, but the this specific action is not maintained (of the ones I linked is a suggested replacement). Would you consider splitting the PR?

I still think something the like python utils/generate_core_modules_with_last_commit_json_file.py . should run also in additional_checks.yaml with some subsequent check (like load to Python and check basic structure or one of the values).

Thanks for the rename. Perhaps the new one is little too long? generate_last_commit_file.py gets most of the important things in.

utils/generate_core_modules_with_last_commit_json_file.py Outdated Show resolved Hide resolved
utils/generate_core_modules_with_last_commit_json_file.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
utils/mkhtml.py Show resolved Hide resolved
@tmszi
Copy link
Member Author

tmszi commented Feb 19, 2022

The release draft action is a great improvement. I'm not sure about the actions/create-release part since it is kind of buried in the context of this PR. The actions/upload-release-asset is more clear, but the this specific action is not maintained (of the ones I linked is a suggested replacement). Would you consider splitting the PR?

Ok. I opened new PR #2224.

I still think something the like python utils/generate_core_modules_with_last_commit_json_file.py . should run also in additional_checks.yaml with some subsequent check (like load to Python and check basic structure or one of the values).

Ok. I created pytest file pytest utils/test_generate_last_commit_file.py and incrorporate into additional_checks.yaml file GitHub workflow action.

Thanks for the rename. Perhaps the new one is little too long? generate_last_commit_file.py gets most of the important things in.

Yes, I agree with you.

I have included all your previous suggestions.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

Getting there. Awesome example of full pytest usage.

utils/test_generate_last_commit_file.py Outdated Show resolved Hide resolved
utils/test_generate_last_commit_file.py Outdated Show resolved Hide resolved
utils/mkhtml.py Show resolved Hide resolved
utils/mkhtml.py Outdated Show resolved Hide resolved
@tmszi
Copy link
Member Author

tmszi commented Feb 20, 2022

I also integrated the remaining suggestions.

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

I'm not sure about the use of UNIX timestamp instead of a readable date and use of sophisticated pytest with depends on an external state, but I think this can be merged.

I don't know where documentation should go, esp. in context of #2224 (automated upload to release draft).

@tmszi
Copy link
Member Author

tmszi commented Apr 13, 2022

I'm not sure about the use of UNIX timestamp instead of a readable date and use of sophisticated pytest with depends on an external state, but I think this can be merged.

All right, I'll change to the readable date format ISO 8601.

@tmszi tmszi requested a review from wenzeslaus April 13, 2022 19:43
@tmszi tmszi merged commit 53ce4fd into OSGeo:main Apr 14, 2022
@tmszi tmszi deleted the generate-local-pgms-json-file-with-last-commit branch April 14, 2022 03:50
@wenzeslaus wenzeslaus changed the title utils/mkhtml.py: generate local JSON file with core modules and their last commit mkhtml: Generate local JSON file with core modules and their last commit Apr 27, 2022
@wenzeslaus
Copy link
Member

This is in 8.2 branch and it is not a general backport material (so no 8.0 which has another fix), so removing the label.

ninsbl pushed a commit to ninsbl/grass that referenced this pull request Oct 26, 2022
… last commit (OSGeo#2140)

For every new pushed repository branch Git tag e.g. 
`git tag -a 8.2.0 -m "Release 8.2.0"` and `git push origin 8.2.0` 
is automatically with GitHub "Create new release draft" action workflow
created new release draft which include downloadable
core_modules_with_last_commit.json and core_modules_with_last_commit.patch file.

During compilation source code without .git dir, this local file is used
instead of getting Git commit from remote GitHub API REST server.

JSON file data structure:

"r.pack": {
    "commit": "547ff44e6aecfb4c9cbf6a4717fc14e521bec0be",
    "date": "2022-02-03T11:10:06+01:00"
},

commit key value is commit hash
date key value is author date (strict ISO 8601 date time format)
ninsbl pushed a commit to ninsbl/grass that referenced this pull request Feb 17, 2023
… last commit (OSGeo#2140)

For every new pushed repository branch Git tag e.g. 
`git tag -a 8.2.0 -m "Release 8.2.0"` and `git push origin 8.2.0` 
is automatically with GitHub "Create new release draft" action workflow
created new release draft which include downloadable
core_modules_with_last_commit.json and core_modules_with_last_commit.patch file.

During compilation source code without .git dir, this local file is used
instead of getting Git commit from remote GitHub API REST server.

JSON file data structure:

"r.pack": {
    "commit": "547ff44e6aecfb4c9cbf6a4717fc14e521bec0be",
    "date": "2022-02-03T11:10:06+01:00"
},

commit key value is commit hash
date key value is author date (strict ISO 8601 date time format)
neteler pushed a commit that referenced this pull request May 29, 2023
Backport of #2550 to G78, fixing Python 3.11 error after deprecation.

* fix #2538
* Use getencoding() where only encoding is needed; getlocale() otherwise

Additional changes:
- sync of `tools/mkhtml.py` with `main` branch
- selected backport from #2140 to get `utils/generate_last_commit_file.py`
- selective sync of `lib/init/grass.py`
neteler pushed a commit to nilason/grass that referenced this pull request Nov 7, 2023
… last commit (OSGeo#2140)

For every new pushed repository branch Git tag e.g. 
`git tag -a 8.2.0 -m "Release 8.2.0"` and `git push origin 8.2.0` 
is automatically with GitHub "Create new release draft" action workflow
created new release draft which include downloadable
core_modules_with_last_commit.json and core_modules_with_last_commit.patch file.

During compilation source code without .git dir, this local file is used
instead of getting Git commit from remote GitHub API REST server.

JSON file data structure:

"r.pack": {
    "commit": "547ff44e6aecfb4c9cbf6a4717fc14e521bec0be",
    "date": "2022-02-03T11:10:06+01:00"
},

commit key value is commit hash
date key value is author date (strict ISO 8601 date time format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants