Skip to content

merge walker #13

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

Closed
wants to merge 14 commits into from
Closed
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
50 changes: 50 additions & 0 deletions .github/workflows/create-puzzle-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create Puzzle Issue

on:
workflow_call:
inputs:
year:
required: true
type: number
description: "The year of the puzzle"
day:
required: true
type: number
description: "The day of the puzzle"
part:
required: true
type: number
description: "The part of the puzzle (1 or 2)"

permissions:
issues: write

jobs:
create-issue:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Create puzzle issue
id: create-issue
run: |
ISSUE_URL=$(gh issue create \
--title "Advent of code - ${{ inputs.year }} day ${{ inputs.day }} part ${{ inputs.part }}" \
--body "Write solution in \`puzzles/year_${{ inputs.year }}/day_${{ inputs.day }}/solution.py\`, and write tests in \`puzzles/year_${{ inputs.year }}/day_${{ inputs.day }}/test_solution.py\` using relative imports")
echo "issue_url=${ISSUE_URL}" >> $GITHUB_OUTPUT

- name: Add sourcery comment
run: |
gh issue comment "${ISSUE_URL}" --body "@sourcery-ai develop - you can read the puzzle statement with \`uv run advent_of_code.py read ${{ inputs.year }} ${{ inputs.day }} ${{ inputs.part }}\`. Run the solution on \`puzzles/year_${{ inputs.year }}/day_${{ inputs.day }}/input.txt\` and write answer to \`puzzles/year_${{ inputs.year }}/day_${{ inputs.day }}/answer_part${{ inputs.part }}.txt\`"
env:
ISSUE_URL: ${{ steps.create-issue.outputs.issue_url }}

- name: Merge develop into main
run: |
git fetch origin
git checkout main
git merge develop
gh pr merge --squash --auto --delete-branch
28 changes: 28 additions & 0 deletions .github/workflows/merge-repos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Merge Repos

on:
repository_dispatch:
types: [merge-repos]

permissions:
contents: write

jobs:
merge-repos:
runs-on: ubuntu-latest
steps:
- name: Check out target repository
uses: actions/checkout@v4
with:
repository: ${{ github.event.client_payload.target_repo }}
token: ${{ secrets.GH_TOKEN }}

- name: Merge source repository
run: |
git remote add source https://github.com/${{ github.event.client_payload.source_repo }}.git
git fetch source
git merge source/main --allow-unrelated-histories

- name: Push changes to target repository
run: |
git push origin main
34 changes: 34 additions & 0 deletions .github/workflows/merge-sourcery-ai-bot-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Auto-merge Sourcery AI Bot PRs

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
merge-sourcery-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'sourcery-ai[bot]'
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Merge Pull Request
run: |
gh pr merge "${{ github.event.pull_request.number }}" \
--squash \
--auto \
--delete-branch \
--repo "${{ github.repository }}"

- name: Merge develop into main
run: |
git fetch origin
git checkout main
git merge develop
gh pr merge --squash --auto --delete-branch
98 changes: 98 additions & 0 deletions .github/workflows/submit-advent-of-code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Submit Advent of Code Solution

on:
push:
branches:
- main
paths:
- 'puzzles/year_*/day_*/answer_part*.txt'
workflow_dispatch:

permissions:
contents: write
issues: write
repository-dispatch: write

env:
AOC_SESSION: ${{ secrets.AOC_SESSION }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
submit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up uv
uses: astral-sh/setup-uv@v4

- name: Install dependencies
run: uv sync

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: puzzles/year_*/day_*/answer_part*.txt

- name: Extract year, day and part from filename
id: extract-info
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "No file changes to process"
exit 0
fi

for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $file =~ puzzles/year_([0-9]+)/day_([0-9]+)/answer_part([12]).txt ]]; then
echo "year=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "day=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
echo "part=${BASH_REMATCH[3]}" >> $GITHUB_OUTPUT
fi
done

- name: Submit solution
id: submit
if: steps.extract-info.outputs.year != ''
continue-on-error: true
run: |
output=$(uv run advent_of_code.py submit ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }} ${{ steps.extract-info.outputs.part }})
echo "submission_result=$output" >> $GITHUB_OUTPUT

- name: Update results in README
if: steps.extract-info.outputs.year != ''
run: uv run advent_of_code.py update-results ${{ steps.extract-info.outputs.year }}

- name: Download part 2 if part 1 was correct
id: download-part2
if: steps.extract-info.outputs.part == '1' && steps.submit.outcome == 'success'
run: |
file_path=$(uv run advent_of_code.py download ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }})
echo "file_path=$file_path" >> $GITHUB_OUTPUT

- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

- name: Commit and push changes
run: |
git add puzzles/year_${{ steps.extract-info.outputs.year }}/day_${{ steps.extract-info.outputs.day }}
git add README.md
git commit -m "Update puzzle files for year ${{ steps.extract-info.outputs.year }} day ${{ steps.extract-info.outputs.day }}"
git push

- name: Trigger create-puzzle-issue workflow
if: steps.download-part2.outputs.file_path != ''
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ env.GH_TOKEN }}
event-type: create-puzzle-issue
client-payload: '{"year": "${{ steps.extract-info.outputs.year }}", "day": "${{ steps.extract-info.outputs.day }}", "part": "2"}'

- name: Merge develop into main
run: |
git fetch origin
git checkout main
git merge develop
gh pr merge --squash --auto --delete-branch
124 changes: 120 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Each day during advent of code this repo solves the latest puzzle and submits the solution - all without human intervention
- All code in this repo was written by `sourcery-ai[bot]`
- Everything was set up by manually writing [five issues](https://github.com/sourcery-ai/autonomous-advent-of-code/labels/inception) and asking `sourcery-ai[bot]` to implement them
- Everything was set up by manually writing [five issues](https://github.com/JohnDaWalka/test-aoc/labels/inception) and asking `sourcery-ai[bot]` to implement them
- Since then everything runs fully autonomously

There are two main processes that work together to solve the puzzles:
Expand Down Expand Up @@ -76,7 +76,123 @@ It will be most useful for handling routine maintenance and clearing your backlo

If you like the sound of this, [join our waitlist](https://getsourcery.netlify.app/) and tell us anything else you want it to do.

#### Footnotes
## Triggering the `merge-repos` Workflow

[^1]: We run this twelve hours after the puzzles are published to avoid interfering with any leaderboards
[^2]: `sourcery-ai[bot]` cannot log into the advent of code website and read the puzzles and input, so we store them in the repository. The advent of code rules ask you not to publish the puzzle text - so we're ROT13 encoding it
To trigger the `merge-repos` workflow, you need to dispatch a repository event with the event type `merge-repos`. You can do this using the GitHub API or the `gh` CLI tool.

### Example using `gh` CLI

```sh
gh api repos/:owner/:repo/dispatches --field event_type=merge-repos --field client_payload='{"source_repo": "source-repo-name", "target_repo": "target-repo-name"}'
```

Replace `:owner` with the repository owner, `:repo` with the repository name, `source-repo-name` with the name of the source repository, and `target-repo-name` with the name of the target repository.

### Example using GitHub API

```sh
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token YOUR_GITHUB_TOKEN" https://api.github.com/repos/:owner/:repo/dispatches -d '{"event_type":"merge-repos","client_payload":{"source_repo":"source-repo-name","target_repo":"target-repo-name"}}'
```

Replace `YOUR_GITHUB_TOKEN` with your GitHub token, `:owner` with the repository owner, `:repo` with the repository name, `source-repo-name` with the name of the source repository, and `target-repo-name` with the name of the target repository.

## Rotating `GH_TOKEN` Regularly

To rotate the `GH_TOKEN` regularly, follow these steps:

1. Generate a new GitHub token with the required permissions.
2. Update the GitHub Secrets in your repository settings with the new token.
3. Update any local environment variables or configuration files that use the `GH_TOKEN`.
4. Monitor the usage of the new token to ensure it is working correctly.
5. Revoke the old token to minimize the risk of unauthorized access.

## Monitoring the Usage of `GH_TOKEN`

To monitor the usage of the `GH_TOKEN`, follow these best practices:

1. Enable GitHub's security features, such as security alerts and vulnerability scanning, to detect any suspicious activity.
2. Regularly review the audit logs in your GitHub repository to track the usage of the `GH_TOKEN`.
3. Set up notifications for any unusual activity or changes in the repository.
4. Use third-party tools or services to monitor the usage of the `GH_TOKEN` and detect any potential security issues.
5. Periodically review and update the permissions assigned to the `GH_TOKEN` to ensure they are still necessary and appropriate.

## Merging Code from Different Branches or Repositories

The repository contains GitHub Actions workflows that automatically merge code from different branches or repositories. These workflows use the `gh pr merge` command with the `--squash`, `--auto`, and `--delete-branch` options.

### Example using `gh pr merge`

```sh
gh pr merge <pull-request-number> --squash --auto --delete-branch
```

Replace `<pull-request-number>` with the number of the pull request you want to merge.

### Example using GitHub Actions Workflow

The following GitHub Actions workflow automatically merges pull requests created by the `sourcery-ai[bot]` user:

```yaml
name: Auto-merge Sourcery AI Bot PRs

on:
pull_request:
types: [opened, synchronize, reopened]

permissions:
contents: write

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

jobs:
merge-sourcery-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'sourcery-ai[bot]'
steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Merge Pull Request
run: |
gh pr merge "${{ github.event.pull_request.number }}" \
--squash \
--auto \
--delete-branch \
--repo "${{ github.repository }}"

- name: Merge develop into main
run: |
git fetch origin
git checkout main
git merge develop
gh pr merge --squash --auto --delete-branch
```

## Poker Coach UI

The Poker Coach UI is an interactive interface for hand analysis and game play. It helps users analyze their poker hands and provides feedback.

### Installation

To install the Poker Coach UI, follow these steps:

1. Ensure you have Python 3.12 or higher installed.
2. Clone the repository:
```sh
git clone https://github.com/sourcery-ai/test-aoc.git
cd test-aoc
```
3. Install the required dependencies:
```sh
pip install -r requirements.txt
```

### Usage

To use the Poker Coach UI, run the following command:
```sh
python -m poker_coach.ui
```

This will open the Poker Coach UI window where you can enter your poker hand and analyze it.
Loading