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

Add automatic version updater script and github action #2359

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/update-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Update Lotus Version

on:
workflow_dispatch: # Allows manual trigger
pull_request:
types: [opened, reopened, synchronize]

jobs:
update-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'

- name: Get latest Lotus version
id: get-version
run: |
# Get all releases and find the first one starting with 'v'
RELEASE_INFO=$(curl -s "https://api.github.com/repos/filecoin-project/lotus/releases" | \
jq -r '[.[] | select(.tag_name | startswith("v"))] | first')

# Extract the tag name
TAG_NAME=$(echo "$RELEASE_INFO" | jq -r .tag_name)

# Extract version number (remove 'v' prefix)
LATEST_VERSION=$(echo $TAG_NAME | sed 's/^v//')

echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV

- name: Run update script
run: |
node update-versions.js ${{ env.LATEST_VERSION }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
title: 'Chore: update Lotus version references to ${{ env.LATEST_VERSION }}'
body: |
Automated PR to update Lotus version references to ${{ env.LATEST_VERSION }}

This PR was automatically generated by GitHub Actions.
branch: update-lotus-version
base: main
delete-branch: true
16 changes: 7 additions & 9 deletions nodes/full-nodes/basic-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,29 @@ To install Lotus on your computer, follow these steps:
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:

```sh
sudo tar -C /usr/local/bin -xzf lotus-X.X.X-linux-amd64.tar.gz
sudo tar -C /usr/local/bin -xzf lotus-1.31.1-linux-amd64.tar.gz
```

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

```sh
cd /usr/local/bin/lotus-X.X.X
cd /usr/local/bin/lotus-1.31.1
```

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

```sh
./lotus daemon
```

7. This will start the Lotus daemon, which will connect to the Filecoin network and start synchronizing with other nodes on the network.
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:
5. This will start the Lotus daemon, which will connect to the Filecoin network and start synchronizing with other nodes on the network.
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:

```sh
./lotus-miner run
```

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



Expand Down
16 changes: 8 additions & 8 deletions nodes/lite-nodes/spin-up-a-lite-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ Before we can build the Lotus binaries, we need to follow a few pre-build steps.
This should output something like:

```output
v1.29.0
v1.31.1
```
3. Using the value returned from the previous command, checkout to the latest release branch:

```shell
git checkout v1.29.0
git checkout v1.31.1
```
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.
{% endtab %}
Expand All @@ -99,12 +99,12 @@ Before we can build the Lotus binaries, we need to follow a few pre-build steps.
This should output something like:

```output
v1.29.0
v1.31.1
```
3. Using the value returned from the previous command, checkout to the latest release branch:

```shell
git checkout v1.29.0
git checkout v1.31.1
```
4. Create the necessary environment variables to allow Lotus to run on M1 architecture:

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

```output
v1.29.0
v1.31.1
```
3. Using the value returned from the previous command, checkout to the latest release branch:

```shell
git checkout v1.29.0
git checkout v1.31.1
```
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).

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

```plaintext
lotus version 1.29.0+mainnet+git.1ff3b360b
lotus version 1.31.1+mainnet+git.1ff3b360b
```
{% endtab %}

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

```plaintext
lotus version 1.29.0+calibnet+git.1ff3b360b
lotus version 1.31.1+calibnet+git.1ff3b360b
```
{% endtab %}
{% endtabs %}
Expand Down
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "filecoin-docs",
"version": "1.0.0",
"description": "<div align=center>",
"main": "update-versions.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"update-versions": "node update-versions.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/filecoin-project/filecoin-docs.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/filecoin-project/filecoin-docs/issues"
},
"homepage": "https://github.com/filecoin-project/filecoin-docs#readme"
}
90 changes: 90 additions & 0 deletions update-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const fs = require('fs');
const path = require('path');

// Get the new version from command line argument
const NEW_VERSION = process.argv[2];

if (!NEW_VERSION) {
console.error('Please provide the new version number as an argument.');
console.error('Usage: node script.js <new_version>');
console.error('Example: node script.js 1.31.2');
process.exit(1);
}

const getAllFiles = (dirPath, arrayOfFiles = []) => {
const files = fs.readdirSync(dirPath);

files.forEach(file => {
const fullPath = path.join(dirPath, file);
if (fs.statSync(fullPath).isDirectory()) {
if (file !== 'preview') {
getAllFiles(fullPath, arrayOfFiles);
}
} else if (path.extname(file) === '.md') {
arrayOfFiles.push(fullPath);
}
});

return arrayOfFiles;
};

function processFiles() {
const files = getAllFiles('.');
let versionToUpdate = null;

// First pass: find the lotus-x.xx.x version
files.forEach(file => {
try {
const content = fs.readFileSync(file, 'utf8');
const lotusVersionMatch = content.match(/lotus-(\d+\.\d+\.\d+)/);

if (lotusVersionMatch) {
versionToUpdate = lotusVersionMatch[1];
console.log(`Found lotus version to update: ${versionToUpdate}`);
return false; // Exit the forEach loop once we find a version
}
} catch (error) {
console.error(`Error reading ${file}:`, error);
}
});

if (!versionToUpdate) {
console.error('No lotus version found in files');
return;
}

// Second pass: update all occurrences of the version
files.forEach(file => {
try {
const content = fs.readFileSync(file, 'utf8');
let processed = content;

// Create regex to match the version with optional lotus- prefix
const versionRegex = new RegExp(`(lotus-)?${versionToUpdate.replace(/\./g, '\\.')}`, 'g');

const matches = content.match(versionRegex);
if (matches) {
matches.forEach(match => {
// If match includes 'lotus-', replace with 'lotus-NEW_VERSION'
// Otherwise just replace with NEW_VERSION
const replacement = match.includes('lotus-') ?
`lotus-${NEW_VERSION}` :
NEW_VERSION;

processed = processed.replace(match, replacement);
});

if (content !== processed) {
fs.writeFileSync(file, processed);
console.log(`Updated in ${file}:`);
console.log(`Found patterns: ${matches.join(', ')}`);
console.log(`Updated to versions containing: ${NEW_VERSION}`);
}
}
} catch (error) {
console.error(`Error processing ${file}:`, error);
}
});
}

processFiles();
Loading