-
Notifications
You must be signed in to change notification settings - Fork 86
Add timestamp metadata / action #491
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74a9e71
Add timestamp metadata / action
brombomb 3093472
Fix script
brombomb 942e19d
Fix Updates and script
brombomb 90d0d03
Fix updated ts
brombomb 6927c42
Github action (not gitlab)
brombomb a822916
Fix tags
brombomb bf0623f
fix tabs
brombomb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import subprocess | ||
| import os | ||
| import yaml | ||
| import glob | ||
|
|
||
| def get_git_dates(path): | ||
| # Get all commit dates for the path | ||
| try: | ||
| # Define patterns for commits to ignore (automated metadata updates) | ||
| ignore_patterns = [ | ||
| "Add timestamp metadata", | ||
| "Implement sorting by newest", | ||
| "Merge updated-apps", | ||
| "Fix YAML formatting", | ||
| "Update manifest metadata", | ||
| "Merge branch", | ||
| "Tag consolidation", | ||
| "llm generated categories", | ||
| "Fix Updates and script", | ||
| "Fix updated timestamps", | ||
| "Implement sorting by newest and last updated in app viewer" | ||
| ] | ||
| ignore_regex = "|".join(ignore_patterns) | ||
|
|
||
| # Use TZ=UTC to get dates in UTC format. | ||
| env = os.environ.copy() | ||
| env["TZ"] = "UTC" | ||
|
|
||
| # Get published (oldest) | ||
| cmd_pub = ["git", "log", "--reverse", "--date=iso-strict-local", "--format=%ad", "--", path] | ||
| output_pub = subprocess.check_output(cmd_pub, env=env).decode("utf-8").strip() | ||
| if not output_pub: | ||
| return None, None | ||
| published = output_pub.splitlines()[0] | ||
|
|
||
| # Get updated (newest, excluding automated commits) | ||
| cmd_upd = [ | ||
| "git", "log", "-1", "--date=iso-strict-local", "--format=%ad", | ||
| "--invert-grep", f"--grep={ignore_regex}", "--extended-regexp", | ||
| "--", path | ||
| ] | ||
| output_upd = subprocess.check_output(cmd_upd, env=env).decode("utf-8").strip() | ||
|
|
||
| # If no "real" update found, use published date | ||
| updated = output_upd if output_upd else published | ||
|
|
||
| return published, updated | ||
| except Exception as e: | ||
| print(f"Error getting dates for {path}: {e}") | ||
| return None, None | ||
|
|
||
| def update_manifest(manifest_path): | ||
| # Get the directory of the app | ||
| app_dir = os.path.dirname(manifest_path) | ||
|
|
||
| published, updated = get_git_dates(app_dir) | ||
| if not published: | ||
| print(f"Skipping {manifest_path} (no git history)") | ||
| return | ||
|
|
||
| # Check if we need to update | ||
| with open(manifest_path, 'r') as f: | ||
| try: | ||
| data = yaml.safe_load(f) | ||
| except Exception as e: | ||
| print(f"Error parsing YAML in {manifest_path}: {e}") | ||
| return | ||
|
|
||
| if data is None: | ||
| data = {} | ||
|
|
||
| changed = False | ||
| # Only set published if it's missing. This preserves historical dates | ||
| # even when running in a shallow clone. | ||
| if not data.get('published'): | ||
| data['published'] = published | ||
| changed = True | ||
|
|
||
| # Always update the 'updated' date to the latest commit | ||
| if data.get('updated') != updated: | ||
| data['updated'] = updated | ||
| changed = True | ||
|
|
||
| if data.get('tags') is None: | ||
| data['tags'] = [] | ||
|
|
||
| if changed: | ||
| print(f"Updating {manifest_path}: published={published}, updated={updated}") | ||
| with open(manifest_path, 'w', encoding='utf-8') as f: | ||
| yaml.dump(data, f, sort_keys=False, default_flow_style=False, explicit_start=True, allow_unicode=True, width=1000) | ||
|
|
||
| import sys | ||
|
brombomb marked this conversation as resolved.
Outdated
|
||
|
|
||
| def main(): | ||
| if len(sys.argv) > 1: | ||
| # Use provided arguments (files or directories) | ||
| manifests = [] | ||
| for arg in sys.argv[1:]: | ||
| if arg.endswith("manifest.yaml"): | ||
| manifests.append(arg) | ||
| elif os.path.isdir(arg): | ||
| m = os.path.join(arg, "manifest.yaml") | ||
| if os.path.exists(m): | ||
| manifests.append(m) | ||
| else: | ||
| # Scan all apps | ||
| manifests = glob.glob("apps/*/manifest.yaml") | ||
|
|
||
| print(f"Checking {len(manifests)} manifests.") | ||
| for m in manifests: | ||
| update_manifest(m) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Update App Metadata | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'apps/**' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| update-metadata: | ||
| runs-on: ubuntu-latest | ||
| if: github.repository_owner == 'tronbyt' # Avoid running on forks by default | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Full history needed for git log analysis | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install dependencies | ||
| run: pip install PyYAML | ||
|
|
||
| - name: Update manifest metadata | ||
| id: update | ||
| run: | | ||
| # Determine modified apps | ||
| if [[ "${{ github.event_before }}" == "0000000000000000000000000000000000000000" ]]; then | ||
| echo "Initial push or new branch, checking all apps..." | ||
| python3 .github/scripts/update_manifests.py | ||
| else | ||
| echo "Performing incremental update for push..." | ||
| TARGETS=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^apps/' | cut -d'/' -f1-2 | sort -u || true) | ||
| if [ -n "$TARGETS" ]; then | ||
| python3 .github/scripts/update_manifests.py $TARGETS | ||
| else | ||
| echo "No apps modified in this push." | ||
| fi | ||
| fi | ||
|
|
||
| - name: Commit and push changes | ||
| run: | | ||
| if [[ -n $(git status --porcelain) ]]; then | ||
| echo "Detected changes in app manifests. Committing updates..." | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add apps/*/manifest.yaml | ||
| git commit -m "chore: auto-update manifest metadata [skip ci]" | ||
| git push | ||
| else | ||
| echo "No metadata updates required." | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.