Skip to content

Commit df9524e

Browse files
authored
Merge pull request #2359 from filecoin-project/bp/lotus-variable
Add automatic version updater script and github action
2 parents 1e029a6 + de57a87 commit df9524e

File tree

5 files changed

+176
-17
lines changed

5 files changed

+176
-17
lines changed

.github/workflows/update-versions.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Update Lotus Version
2+
3+
on:
4+
workflow_dispatch: # Allows manual trigger
5+
pull_request:
6+
types: [opened, reopened, synchronize]
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+
# Get all releases and find the first one starting with 'v'
23+
RELEASE_INFO=$(curl -s "https://api.github.com/repos/filecoin-project/lotus/releases" | \
24+
jq -r '[.[] | select(.tag_name | startswith("v"))] | first')
25+
26+
# Extract the tag name
27+
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r .tag_name)
28+
29+
# Extract version number (remove 'v' prefix)
30+
LATEST_VERSION=$(echo $TAG_NAME | sed 's/^v//')
31+
32+
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
33+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
34+
35+
- name: Run update script
36+
run: |
37+
node update-versions.js ${{ env.LATEST_VERSION }}
38+
39+
- name: Create Pull Request
40+
uses: peter-evans/create-pull-request@v5
41+
with:
42+
commit-message: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
43+
title: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
44+
body: |
45+
Automated PR to update Lotus version references to ${{ env.LATEST_VERSION }}
46+
47+
This PR was automatically generated by GitHub Actions.
48+
branch: update-lotus-version
49+
base: main
50+
delete-branch: true

nodes/full-nodes/basic-setup.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,29 @@ 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.1-linux-amd64.tar.gz
1616
```
1717

18-
3. Replace `X.X.X` with the version number of the release you downloaded.
19-
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:
18+
3. 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:
2019

2120
```sh
22-
cd /usr/local/bin/lotus-X.X.X
21+
cd /usr/local/bin/lotus-1.31.1
2322
```
2423

25-
5. Again, replace `X.X.X` with the version number of the release you downloaded.
26-
6. Run the `lotus` binary file to start the Lotus daemon. You can do this by running the command:
24+
4. Run the `lotus` binary file to start the Lotus daemon. You can do this by running the command:
2725

2826
```sh
2927
./lotus daemon
3028
```
3129

32-
7. This will start the Lotus daemon, which will connect to the Filecoin network and start synchronizing with other nodes on the network.
33-
8. Optionally, you can also run the lotus-miner binary file if you want to participate in the Filecoin mining process. You can do this by running the command:
30+
5. This will start the Lotus daemon, which will connect to the Filecoin network and start synchronizing with other nodes on the network.
31+
6. Optionally, you can also run the lotus-miner binary file if you want to participate in the Filecoin mining process. You can do this by running the command:
3432

3533
```sh
3634
./lotus-miner run
3735
```
3836

39-
9. This will start the Lotus miner, which will use your computer’s computing power to mine new blocks on the Filecoin network.
37+
7. This will start the Lotus miner, which will use your computer’s computing power to mine new blocks on the Filecoin network.
4038

4139

4240

nodes/lite-nodes/spin-up-a-lite-node.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ Before we can build the Lotus binaries, we need to follow a few pre-build steps.
7373
This should output something like:
7474

7575
```output
76-
v1.29.0
76+
v1.31.1
7777
```
7878
3. Using the value returned from the previous command, checkout to the latest release branch:
7979

8080
```shell
81-
git checkout v1.29.0
81+
git checkout v1.31.1
8282
```
8383
4. Done! You can move on to the [Build](https://docs.filecoin.io/nodes/lite-nodes/spin-up-a-lite-node/#build-the-binary) section.
8484
{% endtab %}
@@ -99,12 +99,12 @@ Before we can build the Lotus binaries, we need to follow a few pre-build steps.
9999
This should output something like:
100100

101101
```output
102-
v1.29.0
102+
v1.31.1
103103
```
104104
3. Using the value returned from the previous command, checkout to the latest release branch:
105105

106106
```shell
107-
git checkout v1.29.0
107+
git checkout v1.31.1
108108
```
109109
4. Create the necessary environment variables to allow Lotus to run on M1 architecture:
110110

@@ -132,12 +132,12 @@ Before we can build the Lotus binaries, we need to follow a few pre-build steps.
132132
This should output something like:
133133

134134
```output
135-
v1.29.0
135+
v1.31.1
136136
```
137137
3. Using the value returned from the previous command, checkout to the latest release branch:
138138

139139
```shell
140-
git checkout v1.29.0
140+
git checkout v1.31.1
141141
```
142142
4. If your processor was released later than an AMD Zen or Intel Ice Lake CPU, enable SHA extensions by adding these two environment variables. If in doubt, ignore this command and move on to [the next section](https://docs.filecoin.io/nodes/lite-nodes/spin-up-a-lite-node/#build-the-binary).
143143

@@ -175,7 +175,7 @@ The last thing we need to do to get our node setup is to build the package. The
175175
This will output something like:
176176

177177
```plaintext
178-
lotus version 1.29.0+mainnet+git.1ff3b360b
178+
lotus version 1.31.1+mainnet+git.1ff3b360b
179179
```
180180
{% endtab %}
181181

@@ -200,7 +200,7 @@ The last thing we need to do to get our node setup is to build the package. The
200200
This will output something like:
201201

202202
```plaintext
203-
lotus version 1.29.0+calibnet+git.1ff3b360b
203+
lotus version 1.31.1+calibnet+git.1ff3b360b
204204
```
205205
{% endtab %}
206206
{% endtabs %}

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: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
let versionToUpdate = null;
34+
35+
// First pass: find the lotus-x.xx.x version
36+
files.forEach(file => {
37+
try {
38+
const content = fs.readFileSync(file, 'utf8');
39+
const lotusVersionMatch = content.match(/lotus-(\d+\.\d+\.\d+)/);
40+
41+
if (lotusVersionMatch) {
42+
versionToUpdate = lotusVersionMatch[1];
43+
console.log(`Found lotus version to update: ${versionToUpdate}`);
44+
return false; // Exit the forEach loop once we find a version
45+
}
46+
} catch (error) {
47+
console.error(`Error reading ${file}:`, error);
48+
}
49+
});
50+
51+
if (!versionToUpdate) {
52+
console.error('No lotus version found in files');
53+
return;
54+
}
55+
56+
// Second pass: update all occurrences of the version
57+
files.forEach(file => {
58+
try {
59+
const content = fs.readFileSync(file, 'utf8');
60+
let processed = content;
61+
62+
// Create regex to match the version with optional lotus- prefix
63+
const versionRegex = new RegExp(`(lotus-)?${versionToUpdate.replace(/\./g, '\\.')}`, 'g');
64+
65+
const matches = content.match(versionRegex);
66+
if (matches) {
67+
matches.forEach(match => {
68+
// If match includes 'lotus-', replace with 'lotus-NEW_VERSION'
69+
// Otherwise just replace with NEW_VERSION
70+
const replacement = match.includes('lotus-') ?
71+
`lotus-${NEW_VERSION}` :
72+
NEW_VERSION;
73+
74+
processed = processed.replace(match, replacement);
75+
});
76+
77+
if (content !== processed) {
78+
fs.writeFileSync(file, processed);
79+
console.log(`Updated in ${file}:`);
80+
console.log(`Found patterns: ${matches.join(', ')}`);
81+
console.log(`Updated to versions containing: ${NEW_VERSION}`);
82+
}
83+
}
84+
} catch (error) {
85+
console.error(`Error processing ${file}:`, error);
86+
}
87+
});
88+
}
89+
90+
processFiles();

0 commit comments

Comments
 (0)