I’ve set up a workflow in this GitHub repository to automatically check for valid proxies every 10 minutes. The workflow runs fine, but it’s supposed to create a valid_proxies.txt
file once it’s done, and that file isn’t appearing in my repository.
Here’s what I’ve tried so far:
- The script runs successfully without errors.
- It checks proxies and should save the valid ones in
valid_proxies.txt
. - The file is expected to be updated with each run, but it doesn’t show up.
Does anyone know why this might be happening?
Here is the minimal reproducible example and explanation:
- The script downloads a list of proxies from a GitHub repository and
saves it locally. - It then checks each proxy’s validity by attempting to fetch a
response. - If a proxy is valid, it’s saved to
valid_proxies.txt
.
I even got a message that the files have been uploaded but there is nothing in the valid_proxies.txt
file.
import requests
filename = "proxy_list.txt"
valid_proxies_filename = "valid_proxies.txt"
# Download proxy list
response = requests.get("https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt")
with open(filename, "wb") as file:
file.write(response.content)
# Check proxies
with open(filename, "r") as file, open(valid_proxies_filename, "w") as valid_file:
for proxy in file:
try:
res = requests.get("https://httpbin.org/ip", proxies={"http": proxy.strip(), "https": proxy.strip()})
if res.status_code == 200:
valid_file.write(proxy)
except:
pass
print("Proxy validation complete.")
And here is the action workflow:
name: Run Proxy Checker
on:
schedule:
- cron: '*/10 * * * *' # Runs every 10 minutes
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
pip install --upgrade pip
pip install -r requirements.txt
- name: Run proxy checker script
run: python main.py
- name: Upload valid proxies as an artifact
uses: actions/upload-artifact@v3
with:
name: valid-proxies
path: valid_proxies.txt
2
Answers
Here is the answer that worked for me. I changed the last part of the
actions.yml
codeto this
TL;DR
To change the file in the repo, you need to create and push a commit instead of uploading an artifact.
What’s happening
If you look at the logs from your action runs, right at the bottom of the page, you’ll see
valid-proxies
under Artifacts.actions/upload-artifact@v3
creates an artifact and uploads it with the actions, it does not change the repo.How to commit instead
Now, since you’re trying to add this file (or its changes) to your repo, rather than as an artefact, what you need to do is an actual commit. There may be a workflow in the Actions marketplace you can use, but I usually just script this in my own workflows.
Additional notes
permissions: contents: write
is required if your repo has the protection settings currently recommended.git commit
and thengit push
, but with thatif
statement around thegit commit
, you won’t get an error if the file stays unchanged on a given run.actions/checkout@v4
: that’s the current version, and will make the warnings about deprecated node versions go away.A simpler solution from the marketplace
It looks like all of my code can be replaced by
or maybe
which takes care of everything.
See https://github.com/stefanzweifel/git-auto-commit-action