Skip to content
27 changes: 19 additions & 8 deletions .github/workflows/autocreate-new-mintages.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

name: Automatically create new mintages
name: Automatically add new mintages

on:
schedule:
- cron: '0 0 1 12 *' # At 00:00 on December 1st every year
workflow_dispatch:

jobs:
update-seed:
automatically-add-mintages:
name: Automatically add new mintages
runs-on: ubuntu-latest
steps:
- name: Checkout Open Coin Data
Expand All @@ -18,12 +19,22 @@ jobs:

- name: Set next year variable
run: |
echo "NEXT_YEAR=$(($(date +%Y) + 1))" >> $GITHUB_ENV
NEXT_YEAR=$(($(date +%Y) + 1))
echo "NEXT_YEAR=$NEXT_YEAR" >> $GITHUB_ENV
echo "BRANCH_NAME=add-mintages-$NEXT_YEAR" >> $GITHUB_ENV

- name: Create or update branch on Coinection
- name: Create or update branch
run: |
cd ./ocd
git checkout -b "update-mintages-$NEXT_YEAR"
git fetch --all

if git rev-parse --verify origin/$BRANCH_NAME; then
echo "Branch $BRANCH_NAME already exists in Coinection, checking out..."
git checkout $BRANCH_NAME
else
echo "Branch $BRANCH_NAME does not exist in Coinection, creating new branch..."
git checkout -b $BRANCH_NAME
fi

- name: Run Mintage Update Script
run: |
Expand All @@ -33,7 +44,7 @@ jobs:

- name: Commit and push changes to Open Coin Data
run: |
cd ./ocd/Scripts
cd ./ocd

if git diff --quiet; then
echo "No changes detected in Open Coin Data. Exiting gracefully..."
Expand All @@ -46,5 +57,5 @@ jobs:
git config --global user.name "Coinection"

git add .
git commit -m "Update mintage data for $NEXT_YEAR"
git push origin "update-mintages-$NEXT_YEAR"
git commit -m "Add mintage data for $NEXT_YEAR"
git push origin "$BRANCH_NAME"
3 changes: 2 additions & 1 deletion .github/workflows/update-seed.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

name: Update Coinection Seed
name: Update Coinection seed

on:
pull_request:
Expand All @@ -8,6 +8,7 @@ on:

jobs:
update-seed:
name: Update Coinection seed
runs-on: ubuntu-latest
steps:
- name: Checkout Open Coin Data
Expand Down
20 changes: 8 additions & 12 deletions Scripts/updateMintage.ts → Scripts/add-mintages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,11 @@ class MintageUpdater {
async main(): Promise<void> {
try {
console.log("🚀 Starting mintage update process...");
console.log(`📅 Target year: ${NEXT_YEAR}`);
console.log(`📅 Target year: ${NEXT_YEAR}\n`);

await this.discoverActiveSeries();
console.log(`🔍 Found ${this.activeSeries.length} active series`);

await this.findCoinFiles();
console.log(`🔍 Found ${this.coinFiles.length} coin files in active series`);


const coinsNeedingUpdates = await this.findCoinsNeedingUpdates();

await this.addMintageRows(coinsNeedingUpdates);
Expand All @@ -65,7 +62,7 @@ class MintageUpdater {
const countriesPath = join(this.rootDir, COUNTRIES_DIR);

if (!existsSync(countriesPath)) {
console.warn(`Countries directory not found at: ${countriesPath}`);
console.warn(`Countries directory not found at: ${countriesPath}`);
return;
}

Expand Down Expand Up @@ -133,7 +130,7 @@ class MintageUpdater {
path: filePath
};
} catch (error) {
console.warn(`Warning: Could not parse serie file ${filePath}:`, error);
console.warn(`Warning: Could not parse serie file ${filePath}:`, error);
return null;
}
}
Expand Down Expand Up @@ -177,7 +174,7 @@ class MintageUpdater {
const yearPattern = new RegExp(`^\\|\\s*${year}\\s*\\|`, "m");
return yearPattern.test(content);
} catch (error) {
console.warn(`Warning: Could not check year in ${filePath}:`, error);
console.warn(`Warning: Could not check year in ${filePath}:`, error);
return false;
}
}
Expand All @@ -195,7 +192,7 @@ class MintageUpdater {
}
}

console.log(`Found ${coinsNeedingUpdates.length} coins needing ${NEXT_YEAR} updates`);
console.log(`🕵️ Found ${coinsNeedingUpdates.length} coins needing ${NEXT_YEAR} updates`);
return coinsNeedingUpdates;
}

Expand All @@ -210,10 +207,9 @@ class MintageUpdater {
await this.addMintageRowToCoin(coin);
updatedCount++;
if (updatedCount <= 5) { // Show first 5 updates
console.log(`✓ Added ${NEXT_YEAR} row to ${coin.countryId} ${coin.denomination}`);
}
} catch (error) {
console.error(` Failed to update ${coin.path}:`, error);
console.error(` Failed to update ${coin.path}:`, error);
}
}

Expand Down Expand Up @@ -276,7 +272,7 @@ async function main(): Promise<void> {
// Run the script if this file is executed directly
if (require.main === module) {
main().catch(error => {
console.error("Fatal error:", error);
console.error("Fatal error:", error);
process.exit(1);
});
}
Expand Down
7 changes: 3 additions & 4 deletions Scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "coin-mintage-updater",
"name": "open-coin-data-mintage-updater",
"version": "1.0.0",
"description": "Script to automatically update mintage data for ongoing coin series",
"main": "updateMintage.js",
"description": "Script to automatically add mintage data for next year for ongoing coin series",
"scripts": {
"update": "ts-node updateMintage.ts"
"update": "ts-node add-mintages.ts"
},
"devDependencies": {
"@types/node": "^20.0.0",
Expand Down