Skip to content

Commit 3586556

Browse files
committed
feat: add automatic version updater script
1 parent 1e029a6 commit 3586556

File tree

4 files changed

+130
-2
lines changed

4 files changed

+130
-2
lines changed

.github/workflows/update-versions.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Update Lotus Version
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1' # Runs at 00:00 every Monday
6+
workflow_dispatch: # Allows manual trigger
7+
8+
jobs:
9+
update-version:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '18'
18+
19+
- name: Get latest Lotus version
20+
id: get-version
21+
run: |
22+
LATEST_VERSION=$(curl -s https://api.github.com/repos/filecoin-project/lotus/releases/latest | jq -r .tag_name | sed 's/^v//')
23+
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
24+
25+
- name: Run update script
26+
run: |
27+
node update-versions.js ${{ env.LATEST_VERSION }}
28+
29+
- name: Create Pull Request
30+
uses: peter-evans/create-pull-request@v5
31+
with:
32+
commit-message: 'chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
33+
title: 'chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
34+
body: |
35+
Automated PR to update Lotus version references to ${{ env.LATEST_VERSION }}
36+
37+
This PR updates all references of:
38+
- `lotus-X.X.X`
39+
- Previous lotus version numbers
40+
41+
to `lotus-${{ env.LATEST_VERSION }}`
42+
43+
This PR was automatically generated by GitHub Actions.
44+
branch: update-lotus-version
45+
delete-branch: true

nodes/full-nodes/basic-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ To install Lotus on your computer, follow these steps:
1212
2. Once you have downloaded the binary file, extract the contents to a directory of your choice. For example, if you are using Linux, you can extract the contents to the `/usr/local/bin directory` by running the command:
1313

1414
```sh
15-
sudo tar -C /usr/local/bin -xzf lotus-X.X.X-linux-amd64.tar.gz
15+
sudo tar -C /usr/local/bin -xzf lotus-1.31.3-linux-amd64.tar.gz
1616
```
1717

1818
3. Replace `X.X.X` with the version number of the release you downloaded.
1919
4. After extracting the contents, navigate to the `lotus` directory in your terminal. For example, if you extracted the contents to `/usr/local/bin`, you can navigate to the lotus directory by running the command:
2020

2121
```sh
22-
cd /usr/local/bin/lotus-X.X.X
22+
cd /usr/local/bin/lotus-1.31.3
2323
```
2424

2525
5. Again, replace `X.X.X` with the version number of the release you downloaded.

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "filecoin-docs",
3+
"version": "1.0.0",
4+
"description": "<div align=center>",
5+
"main": "update-versions.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"update-versions": "node update-versions.js"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/filecoin-project/filecoin-docs.git"
13+
},
14+
"keywords": [],
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/filecoin-project/filecoin-docs/issues"
19+
},
20+
"homepage": "https://github.com/filecoin-project/filecoin-docs#readme"
21+
}

update-versions.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
// Get the new version from command line argument
5+
const NEW_VERSION = process.argv[2];
6+
7+
if (!NEW_VERSION) {
8+
console.error('Please provide the new version number as an argument.');
9+
console.error('Usage: node script.js <new_version>');
10+
console.error('Example: node script.js 1.31.2');
11+
process.exit(1);
12+
}
13+
14+
const getAllFiles = (dirPath, arrayOfFiles = []) => {
15+
const files = fs.readdirSync(dirPath);
16+
17+
files.forEach(file => {
18+
const fullPath = path.join(dirPath, file);
19+
if (fs.statSync(fullPath).isDirectory()) {
20+
if (file !== 'preview') {
21+
getAllFiles(fullPath, arrayOfFiles);
22+
}
23+
} else if (path.extname(file) === '.md') {
24+
arrayOfFiles.push(fullPath);
25+
}
26+
});
27+
28+
return arrayOfFiles;
29+
};
30+
31+
function processFiles() {
32+
const files = getAllFiles('.');
33+
// Regex patterns for both actual versions and X.X.X pattern
34+
const versionRegex = /lotus-(\d+\.\d+\.\d+|X\.X\.X)/g;
35+
36+
files.forEach(file => {
37+
try {
38+
const content = fs.readFileSync(file, 'utf8');
39+
let processed = content;
40+
41+
// Find all version patterns in the file
42+
const matches = content.match(versionRegex);
43+
if (matches) {
44+
matches.forEach(oldVersionString => {
45+
const newVersionString = `lotus-${NEW_VERSION}`;
46+
processed = processed.replace(oldVersionString, newVersionString);
47+
});
48+
49+
if (content !== processed) {
50+
fs.writeFileSync(file, processed);
51+
console.log(`Updated versions in: ${file}`);
52+
console.log(`Found patterns: ${matches.join(', ')}`);
53+
console.log(`Updated to: lotus-${NEW_VERSION}`);
54+
}
55+
}
56+
} catch (error) {
57+
console.error(`Error processing ${file}:`, error);
58+
}
59+
});
60+
}
61+
62+
processFiles();

0 commit comments

Comments
 (0)