ipfs / ipfs-docs

📚IPFS documentation platform
https://docs.ipfs.tech
299 stars 409 forks source link

Create automation script to update project version numbers across repos. #1128

Closed johnnymatthews closed 2 years ago

johnnymatthews commented 2 years ago

Throughout this repo we reference specific version numbers for things like Go-IPFS and IPFS Updater.

image

The problem is that where there's updates to these applications, we have to manually go through this repo and update any references. It'd be nice if we had a script that:

  1. Knew which pages to look at.
  2. Found version numbers in those pages.
  3. Checked to see if they were the latest version of the relevant apps/programs.
  4. Updates version numbers where necessary.

We can use this issue to discuss the best way of creating this script.

mrodriguez3313 commented 2 years ago

Just had a question on who would run the script periodically? Would it be automated through a github action in this repo, would it be an automation on some server hosted by PL, or would someone, run the script locally and then push the changes as a pr? The last option seems useless though as I mention it...

As I see it, (quickly glanced through the docs) the pages that would need to be altered in the case of a version update, would be those in "/ipfs-docs/docs/install" is that correct? Before talking about the script, there could be a Markdown hack that we could use to make this easier. "variables" in Markdown

So the whole process would look something like:

  1. We manually replace each version number with a variable in markdown and declare the variable at the top of the page somewhere.
  2. Script would just have to search for that variable in bash or python
  3. Check against respective repositories or dist.ipfs.io directory, either tags/releases/ or somewhere in code that defines version (ex: ipfs-update/config.go
  4. Update the one "variable" in the markdown file

This way it still keeps the portability aspect and the script does not have to go parse the whole document. The changes would be minimal to each doc site

johnnymatthews commented 2 years ago

Would it be automated through a github action in this repo

Yeah this is likely the best option.

"variables" in Markdown

Well this is cool! But I wonder if it'd work within codeblocks:

Lorem ipsum:

```shell
wget https://ipfs.io/downloads/ipfs-updater-1-18-10.dmg


Your process seems logical. We'd probably be able to use the GitHub api to check releases for each major repo (Go-IPFS, IPFS Updater, etc).
mrodriguez3313 commented 2 years ago

So I downloaded the repo and made some basic changes. Turns out the "variable" idea still only behaves like url links☹️. If I do [version]:1.8.0 and try to reference it later like [version]. We actually get this behavior [text](url) version

Well this is cool! But I wonder if it'd work within codeblocks:

And it also did not work with codeblocks, it just rendered it literally like [version]

So if the vue variables is not an option, then the script would have to parse every line in the doc 😟

We'd probably be able to use the GitHub api to check releases for each major repo

Looks like that would be simple enough with: https://docs.github.com/en/rest/releases/releases

johnnymatthews commented 2 years ago

Ok nice, so something like:

curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/ipfs/go-ipfs/releases/latest | jq ".tag_name"

Gives us:

"v0.12.2"

Then we just need some funky regex to run on certain pages to find and replace. This python should work:

import re
regex = r"v\d{1,2}\.\d{1,2}\.\d{1,2}"

test_str = ("---\n"
    "title: Command-line\n"
    "description: Using IPFS through the command-line allows you to do everything that IPFS Desktop can do, but at a more granular level since you can specify which commands to run. Learn how to install it here.\n"
    "current-ipfs-version: v0.12.2\n"
[...]
)

subst = "\"v0.12.2\""
result = re.sub(regex, subst, test_str, 0, re.MULTILINE)

if result:
    print (result)

Haven't tested this though.

mrodriguez3313 commented 2 years ago

It did work, but I had to remove the [...] bc I was getting this error.

$ python3 scripts/docs-updater.py
scripts/docs-updater.py:4: SyntaxWarning: str indices must be integers or slices, not ellipsis; perhaps you missed a comma?
  test_str = ("---\n"
Traceback (most recent call last):
  File "scripts/docs-updater.py", line 4, in <module>
    test_str = ("---\n"
TypeError: string indices must be integers

Then I changed subst=v0.12.0 just to see if it did anything and it did :thumbsup: and it returned:

---
title: Command-line
description: Using IPFS through the command-line allows you to do everything that IPFS Desktop can do, but at a more granular level since you can specify which commands to run. Learn how to install it here.
current-ipfs-version: "v0.12.0"

I can try extending the script to a given page.

"current-ipfs-version: v0.12.2\n"

I'll start with the ipfs-updater tool, and I won't add anything to the metadata(?, idk what that top portion is called) just yet, but that is perfect to have. Then the next step would be checking against the API and running the script if needed. Which I can also take care of.

johnnymatthews commented 2 years ago

I've added the script to PR https://github.com/ipfs/ipfs-docs/pull/1130. Just need to link it up to GitHub actions and we're good to go! Should probably get a Python wiz to review it to (I'm just a lowly docs guys; programming is not my forte).

mrodriguez3313 commented 2 years ago

lol now worries. I program well in python, but stackoverflow is our best friend too 😅

lidel commented 2 years ago

go-ipfs triage notes (cc @BigLep)

laurentsenta commented 2 years ago

Sure,

@mrodriguez3313 @johnnymatthews thanks for looking into this! What about I review the script you shared, and maybe merge it with the CI code that does the version update for go-ipfs (https://github.com/ipfs/ipfs-docs/pull/1081/files)?

BigLep commented 2 years ago

Thanks @laurentsenta . Please proceed with any path that reduces the manual steps here :). Thank you!