Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
124 changes: 124 additions & 0 deletions .github/workflows/hubcap-scheduler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Hubcap Scheduler

on:
schedule:
# Run every hour at :00 for production
- cron: '0 * * * *'
workflow_dispatch:
inputs:
environment:
description: 'Environment to run against'
required: true
default: 'test'
type: choice
options:
- 'test'
- 'production'
dry_run:
description: 'Run in dry-run mode (no PRs created)'
required: false
default: 'true'
type: choice
options:
- 'true'
- 'false'

jobs:
hubcap:
runs-on: ubuntu-latest
timeout-minutes: 45
environment: ${{ github.event.inputs.environment || 'production' }}

steps:
- name: Check out the repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

- name: Configure environment
env:
HUBCAP_CONFIG: ${{ secrets.HUBCAP_CONFIG }}
INPUT_DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
ENVIRONMENT: ${{ github.event.inputs.environment || 'production' }}
run: |
echo "Using $ENVIRONMENT environment configuration"
echo "$HUBCAP_CONFIG" > base_config.json

# Modify config for dry run if requested
if [ "$INPUT_DRY_RUN" = "true" ]; then
echo "Enabling dry-run mode (push_branches = false)"
jq '.push_branches = false' base_config.json > config.json
else
echo "Running in live mode (push_branches = true)"
cp base_config.json config.json
fi

# Set the CONFIG environment variable for hubcap.py
echo "CONFIG<<EOF" >> $GITHUB_ENV
cat config.json >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV

# Log the configuration (without sensitive data)
echo "Configuration summary:"
jq 'del(.user.token)' config.json

- name: Run hubcap
run: |
echo "Starting hubcap execution..."
python3 hubcap.py 2>&1 | tee hubcap.log

- name: Check execution results
if: always()
run: |
echo "=== Execution Summary ==="

# Check for errors
if grep -q 'ERROR' hubcap.log; then
echo "❌ Found ERROR events in execution:"
grep 'ERROR' hubcap.log
echo "EXECUTION_STATUS=failed" >> $GITHUB_ENV
else
echo "✅ No ERROR-level log entries found"
fi

# Check for successful completion
if grep -q 'hubcap execution completed successfully' hubcap.log; then
echo "✅ Hubcap completed successfully"
echo "EXECUTION_STATUS=success" >> $GITHUB_ENV
elif grep -q 'No packages have new versions to update' hubcap.log; then
echo "✅ Hubcap completed successfully (no updates needed)"
echo "EXECUTION_STATUS=success" >> $GITHUB_ENV
else
echo "❌ Hubcap did not complete successfully"
echo "EXECUTION_STATUS=failed" >> $GITHUB_ENV
fi

# Summary of what was processed
if grep -q 'Pushing branches:' hubcap.log; then
echo "📝 Branches processed:"
grep 'Pushing branches:' hubcap.log
fi

- name: Upload execution artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: hubcap-execution-${{ github.event.inputs.environment || 'production' }}-${{ github.run_number }}
path: |
hubcap.log
target/
retention-days: 30

- name: Fail job if execution failed
if: always() && env.EXECUTION_STATUS == 'failed'
run: |
echo "❌ Hubcap execution failed - check logs above"
exit 1
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export CONFIG=$(<config.json)

## Run in test mode

### Local testing
- Set `"repo": "hub.getdbt.com-test"` within `config.json` (or specify some other non-production repository).
- Optional: set `"push_branches": false` within `config.json`.

Expand All @@ -47,6 +48,18 @@ Run:
python3 hubcap.py
```

### GitHub Actions testing
You can also test using the GitHub Actions workflow:
```shell
# Test with dry run (no PRs created)
gh workflow run "Hubcap Scheduler" --field environment=test --field dry_run=true

# Test with live PR creation to test repo
gh workflow run "Hubcap Scheduler" --field environment=test --field dry_run=false
```

See [GITHUB_ACTIONS_SETUP.md](GITHUB_ACTIONS_SETUP.md) for setup instructions.

## Run in production mode

**WARNING:** Use with caution -- _will_ modify state.
Expand Down
162 changes: 162 additions & 0 deletions GITHUB_ACTIONS_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# GitHub Actions Setup Guide

This guide explains how to set up hubcap.py to run on GitHub Actions instead of Heroku.

## Overview

The GitHub Actions workflow (`hubcap-scheduler.yml`) supports:
- **Scheduled execution**: Runs every hour automatically in production
- **Manual execution**: Can be triggered manually for either test or production
- **Dry-run capability**: Can run without creating PRs for testing
- **Environment isolation**: Separate configurations for test and production

## Setup Steps

### 1. Create GitHub Environments

In your GitHub repository, go to **Settings > Environments** and create two environments:

#### Production Environment
- **Name**: `production`
- **Protection rules**:
- ✅ Required reviewers (recommended for production safety)
- ✅ Wait timer: 0 minutes
- **Environment secrets**: See step 2 below

#### Test Environment
- **Name**: `test`
- **Protection rules**: None (allows automatic execution)
- **Environment secrets**: See step 2 below

### 2. Configure Environment Secrets

Each environment needs a `HUBCAP_CONFIG` secret with the appropriate configuration.

#### Production Environment Secret
**Secret name**: `HUBCAP_CONFIG`
**Secret value**:
```json
{
"user": {
"name": "dbt-hubcap",
"email": "buildbot@fishtownanalytics.com",
"token": "ghp_your_production_token_here"
},
"org": "dbt-labs",
"repo": "hub.getdbt.com",
"push_branches": true,
"one_branch_per_repo": true
}
```

#### Test Environment Secret
**Secret name**: `HUBCAP_CONFIG`
**Secret value**:
```json
{
"user": {
"name": "dbt-hubcap-test",
"email": "buildbot+test@fishtownanalytics.com",
"token": "ghp_your_test_token_here"
},
"org": "dbt-labs",
"repo": "hub.getdbt.com-test",
"push_branches": true,
"one_branch_per_repo": true
}
```

### 3. GitHub Personal Access Tokens

Create two GitHub Personal Access Tokens:

#### Production Token
- **Scopes**: `repo`, `workflow`
- **Expiration**: Set appropriate expiration
- **Access**: Must have write access to `dbt-labs/hub.getdbt.com`

#### Test Token
- **Scopes**: `repo`, `workflow`
- **Expiration**: Set appropriate expiration
- **Access**: Must have write access to `dbt-labs/hub.getdbt.com-test`

## Usage

### Automatic Execution (Production)
The workflow runs automatically every hour at `:00` in production mode.

### Manual Execution
You can manually trigger the workflow with different options:

#### Test Environment (Dry Run)
```bash
gh workflow run "Hubcap Scheduler" \
--field environment=test \
--field dry_run=true
```

#### Test Environment (Live)
```bash
gh workflow run "Hubcap Scheduler" \
--field environment=test \
--field dry_run=false
```

#### Production (Manual)
```bash
gh workflow run "Hubcap Scheduler" \
--field environment=production \
--field dry_run=false
```

### Via GitHub Web Interface
1. Go to **Actions > Hubcap Scheduler**
2. Click **Run workflow**
3. Select:
- **Environment**: `test` or `production`
- **Dry run**: `true` (no PRs) or `false` (create PRs)
4. Click **Run workflow**

## Monitoring

### Workflow Status
- View execution history in **Actions** tab
- Each run shows environment, duration, and status
- Failed runs will show error details in logs

### Artifacts
Each execution saves:
- `hubcap.log`: Complete execution log
- `target/`: Cloned repositories and generated files
- Retention: 30 days

### Notifications
Configure notifications in repository settings:
- **Settings > Notifications**
- Enable workflow failure notifications
- Set up Slack/email integration if needed

## Troubleshooting

### Common Issues

**Token Permission Errors**
- Verify token has `repo` and `workflow` scopes
- Check token has write access to target repository
- Ensure token hasn't expired

**Configuration Errors**
- Validate JSON syntax in `HUBCAP_CONFIG` secrets
- Check repository names match intended targets
- Verify user email and name are correct

**Execution Failures**
- Check workflow logs for detailed error messages
- Review `hubcap.log` artifact for application-specific errors
- Verify target repository structure and accessibility

### Getting Help
- Check workflow execution logs
- Review artifacts from failed runs
- Test with dry-run mode first
- Use test environment for debugging
33 changes: 32 additions & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Release instructions

This application is hosted on [Heroku](https://www.heroku.com), but it can also be executed in production mode locally.
This application runs on [GitHub Actions](https://github.com/features/actions) and can also be executed in production mode locally.

**Note**: This application was previously hosted on Heroku. See [GitHub Actions Setup Guide](GITHUB_ACTIONS_SETUP.md) for current deployment instructions.

## Design overview
It is designed to do the following:
Expand Down Expand Up @@ -84,3 +86,32 @@ heroku https://git.heroku.com/dbt-hubcap.git (push)
origin git@github.com:dbt-labs/hubcap.git (fetch)
origin git@github.com:dbt-labs/hubcap.git (push)
```

## GitHub Actions production setup

**Current deployment method**. See [GITHUB_ACTIONS_SETUP.md](GITHUB_ACTIONS_SETUP.md) for detailed setup instructions.

### Overview
- **Schedule**: Runs automatically every hour at `:00`
- **Environments**: Separate `production` and `test` environments
- **Configuration**: Environment-specific secrets containing JSON configuration
- **Manual execution**: Can be triggered manually via GitHub UI or CLI

### Quick setup
1. Create `production` and `test` environments in repository settings
2. Add `HUBCAP_CONFIG` secret to each environment with appropriate JSON configuration
3. The workflow runs automatically on schedule or can be triggered manually

### Manual execution examples
```bash
# Test environment with dry run (no PRs created)
gh workflow run "Hubcap Scheduler" --field environment=test --field dry_run=true

# Production environment (live)
gh workflow run "Hubcap Scheduler" --field environment=production --field dry_run=false
```

### Monitoring
- View execution logs in repository **Actions** tab
- Each run creates artifacts with logs and generated files
- Failed executions send notifications (if configured)