Skip to content
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

Add GitHub Actions workflow for secret update reminders #211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/scripts/check_and_alert_secret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os
from datetime import datetime, timezone

from github import Github


def main():
threshold_days = 50
token = os.getenv("GH_TOKEN")
repo_name = os.getenv("GITHUB_REPOSITORY")

g = Github(token)
repo = g.get_repo(repo_name)
for secret in repo.get_secrets():
secret_name = secret.name
if "linkedin" in secret_name.lower():
updated_at = secret.updated_at
today = datetime.now(timezone.utc)
days_since = (today - updated_at).days
print(
f"Secret '{secret_name}' last updated at: {updated_at} ({days_since} days ago)"
)

if days_since >= threshold_days:
issue_title = "Secret Update Reminder"
issue_body = (
f"The secret **{secret_name}** was last updated **{days_since}** days ago.\n\n"
"Please update this secret as soon as possible."
)
issues = repo.get_issues(state="open")
issue = next(
(i for i in issues if i.title == issue_title),
None,
)
if issue:
issue.create_comment(issue_body)
print(f"Comment added to issue: {issue.html_url}")
else:
issue = repo.create_issue(title=issue_title, body=issue_body)
print(f"Issue created: {issue.html_url}")
else:
print("Secret is up-to-date; no alert needed.")


if __name__ == "__main__":
main()
35 changes: 35 additions & 0 deletions .github/workflows/secret-reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Secret Update Reminder

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
check_secret:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install dependencies
run: |
pip install --upgrade pip
pip install PyGithub

- name: Create GitHub App Token
id: create_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Run secret check and alert script
run: python .github/scripts/check_and_alert_secret.py
env:
GH_TOKEN: ${{ steps.create_token.outputs.token }}