Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sealldeveloper committed Oct 17, 2024
2 parents 404bea8 + ea75a6e commit f287ad4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/autocheckcombos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
branches:
- main
paths:
- 'data/originalMappings.csv' # This will trigger for any file change in the data directory
- 'data/originalMappings.csv'
pull_request:
branches:
- main
paths:
- 'data/originalMappings.csv' # This will trigger for any file change in the data directory
- 'data/originalMappings.csv'
schedule:
- cron: '0 0 1 * *' #once a month

Expand All @@ -28,7 +28,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9' # Specify your required Python version
python-version: '3.9'

- name: Install dependencies
id: dependencies
Expand All @@ -44,17 +44,23 @@ jobs:
id: update_mappings
run: |
NEW_CANDIDATES_FOUND=false
CHANGES=""
while IFS= read -r line; do
if [[ "$line" =~ ^[0-9] ]]; then
NEW_CANDIDATES_FOUND=true
ASCII_NUM=$(echo $line | cut -d',' -f1)
NEW_PYTHON_CODE=$(echo $line | cut -d',' -f2)
OLD_PYTHON_CODE=$(grep "^$ASCII_NUM," data/originalMappings.csv | cut -d',' -f2)
sed -i "s/^$ASCII_NUM,.*/$ASCII_NUM,$NEW_PYTHON_CODE/" data/originalMappings.csv
CHANGES+="- ASCII $ASCII_NUM: '$OLD_PYTHON_CODE' → '$NEW_PYTHON_CODE'\n"
fi
done < result.txt
if [ "$NEW_CANDIDATES_FOUND" = true ]; then
echo "new_candidates=true" >> $GITHUB_OUTPUT
echo "changes<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "new_candidates=false" >> $GITHUB_OUTPUT
fi
Expand All @@ -66,14 +72,32 @@ jobs:
- name: Create or Update Pull Request
if: steps.update_mappings.outputs.new_candidates == 'true'
uses: peter-evans/create-pull-request@v5
id: cpr
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "Update originalMappings.csv with shorter candidates"
body: "This PR updates data/originalMappings.csv with new shorter candidates found by find-num.py."
title: "🔄 Update originalMappings.csv with Shorter Candidates"
body: |
## 🚀 Automatic Shorter Candidates
This PR updates `data/originalMappings.csv` with new shorter candidates discovered by `find-num.py`.
### 📊 Changes
The following entries in the mappings have been updated:
```
${{ steps.update_mappings.outputs.changes }}
```
Enjoy 🎉
base: main
branch: update-original-mappings
commit-message: "Update originalMappings.csv with shorter candidates"
delete-branch: false

- name: Output Pull Request Number
if: steps.cpr.outputs.pull-request-number
run: echo "pull_request_number=${{ steps.cpr.outputs.pull-request-number }}" >> $GITHUB_OUTPUT

- name: Upload Existing Combinations Log
if: steps.update_mappings.outputs.new_candidates == 'false'
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ on:
branches: ["main"]
push:
branches: ["main"]
workflow_dispatch:
workflow_run:
workflows: ["Find Shorter Candidates"]
types:
- completed

jobs:
verify-python-code:
runs-on: ${{ matrix.os }}
if: >
github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'update-original-mappings')
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
Expand All @@ -19,12 +25,19 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout PR if exists
if: github.event_name == 'workflow_run' && github.event.workflow_run.pull_requests[0]
run: |
gh pr checkout ${{ github.event.workflow_run.pull_requests[0].number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -37,7 +50,7 @@ jobs:
run: python verification.py

- name: Check if verification passed
shell: bash # Use Bash for this step
shell: bash
run: |
if [ $? -eq 0 ]; then
echo "Verification passed for Python ${{ matrix.python-version }} on ${{ matrix.os }}."
Expand Down

0 comments on commit f287ad4

Please sign in to comment.