Skip to content

Commit 0ea434b

Browse files
authored
Merge pull request #201 from JaclynCodes/copilot/update-environment-variables
Add automated dependency update workflow with configurable environment variables :)
2 parents 0820a49 + 17eae1b commit 0ea434b

File tree

3 files changed

+209
-0
lines changed

3 files changed

+209
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Update Dependencies
2+
3+
on:
4+
schedule:
5+
# Run at 9:00 AM UTC every Monday
6+
- cron: 0 9 * * 1
7+
# Allow manual runs
8+
workflow_dispatch:
9+
inputs:
10+
package:
11+
description: >
12+
Specific package to update (e.g., numpy, librosa).
13+
Leave empty to check all packages.
14+
required: false
15+
version:
16+
description: >
17+
Target version for the package. Leave empty to use latest.
18+
required: false
19+
20+
env:
21+
PYTHON_VERSION: 3.11
22+
PIP_VERSION: 24.0
23+
24+
jobs:
25+
check-and-update:
26+
runs-on: ubuntu-latest
27+
if: github.repository_owner == 'JaclynCodes'
28+
permissions:
29+
contents: write # Needed to push changes
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
with:
34+
# Use default token for now, can be updated to use PAT if needed
35+
token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Set Git author
38+
run: |
39+
git config user.name "github-actions[bot]"
40+
git config user.email "github-actions[bot]@users.noreply.github.com"
41+
42+
- name: Setup Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: ${{ env.PYTHON_VERSION }}
46+
47+
- name: Upgrade pip
48+
run: |
49+
python -m pip install --upgrade pip==${{ env.PIP_VERSION }}
50+
51+
- name: Install dependencies
52+
run: |
53+
pip install -r requirements.txt
54+
55+
- name: Check for updates
56+
id: check_updates
57+
run: |
58+
# Install pip-tools for dependency management
59+
pip install pip-tools
60+
61+
# Check for outdated packages
62+
echo "Checking for outdated packages..."
63+
pip list --outdated > outdated.txt
64+
cat outdated.txt
65+
66+
if [ -s outdated.txt ]; then
67+
echo "updates_available=true" >> $GITHUB_OUTPUT
68+
else
69+
echo "updates_available=false" >> $GITHUB_OUTPUT
70+
fi
71+
72+
- name: Update dependencies
73+
if: steps.check_updates.outputs.updates_available == 'true'
74+
run: |
75+
# Create a new branch for the update
76+
BRANCH_NAME="automated/update-dependencies-$(date +%Y%m%d)"
77+
git checkout -b "$BRANCH_NAME"
78+
79+
# If specific package and version provided, update that
80+
if [ -n "${{ inputs.package }}" ]; then
81+
if [ -n "${{ inputs.version }}" ]; then
82+
echo "Updating ${{ inputs.package }} to version \
83+
${{ inputs.version }}"
84+
# Use word boundaries to match exact package name
85+
sed -i "s/^${{ inputs.package }}[>=<].*/${{ inputs.package }}==\
86+
${{ inputs.version }}/" requirements.txt
87+
else
88+
echo "Updating ${{ inputs.package }} to latest \
89+
compatible version"
90+
# Get latest version compatible with constraints
91+
LATEST=$(pip index versions "${{ inputs.package }}" | \
92+
grep "Available versions:" | head -1 | cut -d: -f2 | \
93+
tr ',' '\n' | head -1 | xargs)
94+
if [ -z "$LATEST" ]; then
95+
echo "Error: Could not determine latest version for \
96+
${{ inputs.package }}"
97+
exit 1
98+
fi
99+
# Use word boundaries to match exact package name
100+
sed -i "s/^${{ inputs.package }}[>=<].*/${{ inputs.package }}>=\
101+
$LATEST/" requirements.txt
102+
fi
103+
else
104+
echo "No specific package provided for update."
105+
echo "Please run manually with package name to update."
106+
echo "Bulk updates require manual review and are not \
107+
automated."
108+
exit 0
109+
fi
110+
111+
# Commit changes if there are any
112+
if git diff --quiet requirements.txt; then
113+
echo "No changes to commit"
114+
exit 0
115+
else
116+
git add requirements.txt
117+
COMMIT_MSG="Update ${{ inputs.package }} dependency"
118+
git commit -m "$COMMIT_MSG"
119+
git push origin "$BRANCH_NAME"
120+
121+
# Create PR using GitHub CLI would go here if available
122+
echo "Branch $BRANCH_NAME created with updates"
123+
fi

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Welcome to the Symphonic-Joules documentation! This directory contains comprehen
1212
- **[Performance Optimization](performance-optimization.md)** - Best practices for efficient code
1313
- **[Test Performance Guide](test-performance-guide.md)** - Writing fast and efficient tests
1414
- **[Archive Review Process](archive-review-process.md)** - Guidelines for reviewing uploaded code and archives
15+
- **[GitHub Workflows](workflows.md)** - Automated workflows and CI/CD documentation
1516
- **[FAQ](faq.md)** - Frequently asked questions
1617

1718
## 🎯 Quick Navigation
@@ -27,6 +28,7 @@ Welcome to the Symphonic-Joules documentation! This directory contains comprehen
2728
- [Architecture Overview](architecture.md)
2829
- [Archive Review Process](archive-review-process.md)
2930
- [Test Performance Guide](test-performance-guide.md)
31+
- [GitHub Workflows](workflows.md)
3032
- [API Reference](api-reference.md)
3133

3234
## 🔄 Keeping Documentation Updated

docs/workflows.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# GitHub Workflows
2+
3+
This document describes the GitHub Actions workflows used in the Symphonic-Joules project.
4+
5+
## Available Workflows
6+
7+
### Update Dependencies
8+
9+
**File:** `.github/workflows/update_dependencies.yml`
10+
11+
**Purpose:** Automates checking and updating Python package dependencies.
12+
13+
**Triggers:**
14+
- **Schedule:** Runs automatically every Monday at 9:00 AM UTC
15+
- **Manual:** Can be triggered manually via GitHub Actions UI
16+
17+
**Environment Variables:**
18+
- `PYTHON_VERSION`: The Python version used for updates (default: 3.11)
19+
- `PIP_VERSION`: The pip version used (default: 24.0)
20+
21+
**Manual Trigger Options:**
22+
- `package`: Specify a particular package to update (e.g., `numpy`, `librosa`)
23+
- `version`: Specify the target version for the package (leave empty for latest)
24+
25+
**What It Does:**
26+
1. Checks out the repository
27+
2. Sets up Python environment with configured version
28+
3. Installs current dependencies
29+
4. Checks for outdated packages
30+
5. (Optional) Updates specific package if provided
31+
6. Creates a new branch with updates
32+
7. Commits and pushes changes
33+
34+
**Usage Examples:**
35+
36+
**Check all packages for updates:**
37+
- Go to Actions tab
38+
- Select "Update Dependencies" workflow
39+
- Click "Run workflow"
40+
- Leave inputs empty
41+
- Click "Run workflow"
42+
43+
**Update specific package:**
44+
- Go to Actions tab
45+
- Select "Update Dependencies" workflow
46+
- Click "Run workflow"
47+
- Enter package name (e.g., `numpy`)
48+
- Optionally enter version (e.g., `1.24.0`)
49+
- Click "Run workflow"
50+
51+
**Notes:**
52+
- The workflow only runs if the repository owner is `JaclynCodes`
53+
- Changes are pushed to a new branch with format `automated/update-dependencies-YYYYMMDD`
54+
- Manual review is recommended before merging dependency updates
55+
- The workflow uses GitHub Actions bot for commits
56+
57+
## Other Workflows
58+
59+
### CI (Continuous Integration)
60+
**File:** `.github/workflows/blank.yml`
61+
- Runs on push and pull requests to main branch
62+
- Performs linting, testing, and builds
63+
64+
### CodeQL Advanced
65+
**File:** `.github/workflows/codeql.yml`
66+
- Security scanning workflow
67+
- Runs on schedule and PR events
68+
69+
### License Check
70+
**File:** `.github/workflows/license-check.yml`
71+
- Validates license compliance
72+
73+
### Static Content Deployment
74+
**File:** `.github/workflows/static.yml`
75+
- Deploys static content to GitHub Pages
76+
77+
## Contributing
78+
79+
When adding or modifying workflows:
80+
1. Follow YAML best practices
81+
2. Use environment variables for configuration
82+
3. Add appropriate documentation
83+
4. Test workflows before merging
84+
5. Follow the repository's contribution guidelines

0 commit comments

Comments
 (0)