Skip to content

Commit f548caf

Browse files
committed
feat: Add automated weekly database updates
- Schedule weekly runs (Mondays 9:00 UTC) - Trigger on database source file changes - Auto-commit and release when database changes - Replace old release-database.yml with comprehensive workflow The database is curated from internal/database/ source files. To add new packages, update the Go source and the workflow will automatically regenerate and release.
1 parent 8d08408 commit f548caf

File tree

2 files changed

+137
-79
lines changed

2 files changed

+137
-79
lines changed

.github/workflows/release-database.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Automated database update workflow
2+
# - Runs weekly to ensure crypto database stays current
3+
# - Triggers on source database changes
4+
# - Can be manually triggered
5+
6+
name: Update Database
7+
8+
on:
9+
schedule:
10+
# Run every Monday at 9:00 UTC
11+
- cron: '0 9 * * 1'
12+
push:
13+
branches: [main]
14+
paths:
15+
- 'internal/database/**'
16+
- 'pkg/crypto/quantum.go'
17+
- 'pkg/crypto/algorithms.go'
18+
workflow_dispatch:
19+
inputs:
20+
force_release:
21+
description: 'Force release even if no changes'
22+
required: false
23+
default: 'false'
24+
type: boolean
25+
26+
permissions:
27+
contents: write
28+
29+
jobs:
30+
update:
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Set up Go
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version: '1.22'
42+
43+
- name: Store current database hash
44+
id: before
45+
run: |
46+
if [ -f data/crypto-database.json ]; then
47+
echo "hash=$(sha256sum data/crypto-database.json | cut -d' ' -f1)" >> $GITHUB_OUTPUT
48+
else
49+
echo "hash=none" >> $GITHUB_OUTPUT
50+
fi
51+
52+
- name: Generate updated database
53+
run: |
54+
go run cmd/gendb/main.go > data/crypto-database.json
55+
echo "Generated database with $(jq '.packages | length' data/crypto-database.json) packages"
56+
57+
- name: Check for changes
58+
id: changes
59+
run: |
60+
NEW_HASH=$(sha256sum data/crypto-database.json | cut -d' ' -f1)
61+
if [ "${{ steps.before.outputs.hash }}" != "$NEW_HASH" ] || [ "${{ inputs.force_release }}" == "true" ]; then
62+
echo "changed=true" >> $GITHUB_OUTPUT
63+
echo "Database has changed or force release requested"
64+
else
65+
echo "changed=false" >> $GITHUB_OUTPUT
66+
echo "No changes detected"
67+
fi
68+
69+
- name: Get database stats
70+
if: steps.changes.outputs.changed == 'true'
71+
id: stats
72+
run: |
73+
PACKAGES=$(jq '.packages | length' data/crypto-database.json)
74+
VERSION=$(jq -r '.version' data/crypto-database.json)
75+
echo "packages=$PACKAGES" >> $GITHUB_OUTPUT
76+
echo "version=$VERSION" >> $GITHUB_OUTPUT
77+
78+
- name: Commit updated database
79+
if: steps.changes.outputs.changed == 'true'
80+
run: |
81+
git config user.name "github-actions[bot]"
82+
git config user.email "github-actions[bot]@users.noreply.github.com"
83+
git add data/crypto-database.json
84+
git commit -m "chore(db): Update crypto database
85+
86+
- Packages: ${{ steps.stats.outputs.packages }}
87+
- Version: ${{ steps.stats.outputs.version }}
88+
- Updated: $(date -u +%Y-%m-%d)"
89+
git push
90+
91+
- name: Generate release tag
92+
if: steps.changes.outputs.changed == 'true'
93+
id: tag
94+
run: |
95+
TAG="db-v${{ steps.stats.outputs.version }}-$(date +%Y%m%d)"
96+
echo "tag=$TAG" >> $GITHUB_OUTPUT
97+
98+
- name: Create database release
99+
if: steps.changes.outputs.changed == 'true'
100+
uses: softprops/action-gh-release@v1
101+
with:
102+
tag_name: ${{ steps.tag.outputs.tag }}
103+
name: "Database Update ${{ steps.tag.outputs.tag }}"
104+
body: |
105+
## Automated Database Update
106+
107+
**Packages:** ${{ steps.stats.outputs.packages }}
108+
**Version:** ${{ steps.stats.outputs.version }}
109+
**Updated:** ${{ github.event.repository.updated_at }}
110+
111+
### Changes
112+
This is an automated weekly update to ensure the crypto database stays current.
113+
114+
### Usage
115+
```bash
116+
# Update your local database
117+
cryptodeps db update
118+
119+
# Or download directly
120+
curl -LO https://github.com/csnp/qramm-cryptodeps/releases/download/${{ steps.tag.outputs.tag }}/crypto-database.json
121+
```
122+
files: data/crypto-database.json
123+
draft: false
124+
prerelease: false
125+
126+
- name: Summary
127+
run: |
128+
if [ "${{ steps.changes.outputs.changed }}" == "true" ]; then
129+
echo "### Database Updated :white_check_mark:" >> $GITHUB_STEP_SUMMARY
130+
echo "" >> $GITHUB_STEP_SUMMARY
131+
echo "- **Packages:** ${{ steps.stats.outputs.packages }}" >> $GITHUB_STEP_SUMMARY
132+
echo "- **Release:** ${{ steps.tag.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
133+
else
134+
echo "### No Updates Needed :information_source:" >> $GITHUB_STEP_SUMMARY
135+
echo "" >> $GITHUB_STEP_SUMMARY
136+
echo "The database is already up to date." >> $GITHUB_STEP_SUMMARY
137+
fi

0 commit comments

Comments
 (0)