fix findnum shorter check #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Find Shorter Candidates | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'data/originalMappings.csv' | |
- 'findnum.py' | |
pull_request: | |
branches: | |
- main | |
paths: | |
- 'data/originalMappings.csv' | |
- 'findnum.py' | |
schedule: | |
- cron: '0 0 1 * *' #once a month | |
jobs: | |
find-shorter-candidates: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
id: dependencies | |
run: | | |
sudo apt-get install -y expect | |
- name: Run findnum.py | |
id: find_num | |
run: | | |
unbuffer python findnum.py --range 255 | tee result.txt | |
- name: Update originalMappings.csv | |
id: update_mappings | |
run: | | |
NEW_CANDIDATES_FOUND=false | |
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) | |
OLD_LENGTH=${#OLD_PYTHON_CODE} | |
NEW_LENGTH=${#NEW_PYTHON_CODE} | |
DIFFERENCE=$((OLD_LENGTH - NEW_LENGTH)) | |
ASCII_CHAR=$(printf "\\$(printf '%03o' "$ASCII_NUM")") | |
# Update CSV file | |
sed -i "s/^$ASCII_NUM,.*/$ASCII_NUM,$NEW_PYTHON_CODE/" data/originalMappings.csv | |
fi | |
done < result.txt | |
if [ "$NEW_CANDIDATES_FOUND" = true ]; then | |
echo "new_candidates=true" >> $GITHUB_OUTPUT | |
else | |
echo "new_candidates=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Remove result.txt if new candidates found | |
if: steps.update_mappings.outputs.new_candidates == 'true' | |
run: rm result.txt | |
- 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: | | |
## 🚀 Automatic Shorter Candidates | |
This PR updates `data/originalMappings.csv` with new shorter candidates discovered by `findnum.py`. | |
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' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: results-log | |
path: result.txt |