Skip to content

Commit

Permalink
Added check release for Trezor. Fixed seedsigner check release
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirosson committed Oct 2, 2023
1 parent 797d7ca commit c8d9039
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 1 deletion.
43 changes: 43 additions & 0 deletions .github/workflows/check-changelog-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check Releases Template

on:
workflow_call:
inputs:
item-id:
required: true
type: string
changelog-url:
required: true
type: string

jobs:
check-release:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 14

- name: Install dependencies
run: npm install
working-directory: scripts

- name: Run script
run: node github-release.js ${{ inputs.item-id }} ${{ inputs.changelog-url }}
working-directory: scripts

- name: Create Pull Request
uses: peter-evans/[email protected]
with:
title: "New ${{ inputs.item-id }} release"
commit-message: "New ${{ inputs.item-id }} release"
branch: "${{ inputs.item-id }}/new-release"
add-paths: "items/*.json"
assignees: "${{ secrets.ASSIGNEE }}"
10 changes: 10 additions & 0 deletions .github/workflows/check-releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ jobs:
item-id: krux
github-org: selfcustody
github-repo: krux
trezor-model-one:
uses: ./.github/workflows/check-changelog-template.yml
with:
item-id: trezor-model-one
changelog-url: https://github.com/trezor/trezor-firmware/blob/master/legacy/firmware/CHANGELOG.md
trezor-model-t:
uses: ./.github/workflows/check-changelog-template.yml
with:
item-id: trezor-model-t
changelog-url: https://raw.githubusercontent.com/trezor/trezor-firmware/master/core/CHANGELOG.md
118 changes: 118 additions & 0 deletions scripts/github-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
require('dotenv').config();
const fs = require('fs');
const axios = require('axios');

const itemId = process.argv[2];
const changelogUrl = process.argv[3];

var latestVersion
var latestReleaseDate

axios
.get(changelogUrl)
.then((response) => {
var body = response.data
// Split the content into lines
const lines = body.split('\n');

// Find the first line starting with "##"
const regex = /^## \[([\d.]+)\] \(([^)]+)\)/;
for (const line of lines) {
const match = line.match(regex);
if (match) {
latestVersion = "v" + match[1];
latestReleaseDate = formatDate(match[2]);
break;
}
}

console.log(`Sanitized version: ${latestVersion}`);
console.log(`Release Date: ${latestReleaseDate}`);
updateJson(itemId, latestVersion, latestReleaseDate);

})
.catch((error) => {
console.error('Error fetching release information:', error.message);
process.exit(1);
});

function formatDate(inputDate) {
// Define months for formatting
const months = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];

// Split the input date string into parts
const parts = inputDate.match(/(\d+)\w+\s(\w+)\s(\d+)/);

if (parts && parts.length === 4) {
const day = parseInt(parts[1]);
const monthIndex = months.indexOf(parts[2]);
const year = parseInt(parts[3]);

if (monthIndex !== -1) {
// Create a JavaScript Date object
const date = new Date(year, monthIndex, day);

// Format the date in the desired output format (e.g., "Jul 27, 2023")
const formattedDate = `${months[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
return formattedDate;
}
}

// Return the original input if parsing fails
return inputDate;
}

function updateJson(itemId, latestVersion, latestReleaseDate) {
// Define the path to your JSON file.
const filePath = `./items/${itemId}.json`;

// Read the JSON file.
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading JSON file:', err);
return;
}

try {
const wallet = JSON.parse(data);
var modifyJson = false

console.log("Updating hardware wallet firmware")

var currentVersion = wallet["firmware"]["latest-version"].value
console.log("Current version found: " + currentVersion)
if (latestVersion !== currentVersion) {
wallet["firmware"]["latest-version"].value = latestVersion
modifyJson = true
}

var currentReleaseDate = wallet["firmware"]["latest-release-date"].value
if (latestReleaseDate !== currentReleaseDate) {
wallet["firmware"]["latest-release-date"].value = latestReleaseDate
modifyJson = true
}
console.log("Current Release date found: " + currentReleaseDate)

if (modifyJson) {
// Convert the modified object back to a JSON string.
const updatedJsonString = JSON.stringify(wallet, null, 2);

// Write the updated JSON string back to the file.
fs.writeFile(filePath, updatedJsonString, (writeErr) => {
if (writeErr) {
console.error('Error writing JSON file:', writeErr);
} else {
console.log('JSON file updated successfully.');
}
});
}

} catch (parseError) {
console.error('Error parsing JSON:', parseError);
process.exit(1);
}
});
}
2 changes: 1 addition & 1 deletion scripts/github-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function ignoreVersion(itemId, latestVersion) {
return true
}

if (itemId == "seedsigner" && !latestVersion.endsWith("_EXP")) {
if (itemId == "seedsigner" && latestVersion.endsWith("_EXP")) {
return true
}

Expand Down

0 comments on commit c8d9039

Please sign in to comment.