diff --git a/.github/workflows/autocreate-new-mintages.yml b/.github/workflows/autocreate-new-mintages.yml index fd662d6d..00152228 100644 --- a/.github/workflows/autocreate-new-mintages.yml +++ b/.github/workflows/autocreate-new-mintages.yml @@ -1,5 +1,5 @@ -name: Automatically create new mintages +name: Automatically add new mintages on: schedule: @@ -7,7 +7,8 @@ on: workflow_dispatch: jobs: - update-seed: + automatically-add-mintages: + name: Automatically add new mintages runs-on: ubuntu-latest steps: - name: Checkout Open Coin Data @@ -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: | @@ -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..." @@ -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" \ No newline at end of file + git commit -m "Add mintage data for $NEXT_YEAR" + git push origin "$BRANCH_NAME" diff --git a/.github/workflows/update-seed.yml b/.github/workflows/update-seed.yml index 9a99c642..6cc29826 100644 --- a/.github/workflows/update-seed.yml +++ b/.github/workflows/update-seed.yml @@ -1,5 +1,5 @@ -name: Update Coinection Seed +name: Update Coinection seed on: pull_request: @@ -8,6 +8,7 @@ on: jobs: update-seed: + name: Update Coinection seed runs-on: ubuntu-latest steps: - name: Checkout Open Coin Data diff --git a/Scripts/updateMintage.ts b/Scripts/add-mintages.ts similarity index 91% rename from Scripts/updateMintage.ts rename to Scripts/add-mintages.ts index 965b2ea8..d9fb0f9e 100644 --- a/Scripts/updateMintage.ts +++ b/Scripts/add-mintages.ts @@ -38,14 +38,11 @@ class MintageUpdater { async main(): Promise { 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); @@ -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; } @@ -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; } } @@ -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; } } @@ -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; } @@ -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); } } @@ -276,7 +272,7 @@ async function main(): Promise { // 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); }); } diff --git a/Scripts/package.json b/Scripts/package.json index 99cd619a..82a69a9e 100644 --- a/Scripts/package.json +++ b/Scripts/package.json @@ -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",