skip to Main Content

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.

enter image description here

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


  1. Chosen as BEST ANSWER

    Here is the answer that worked for me. I changed the last part of the actions.yml code

    - name: Upload valid proxies as an artifact
            uses: actions/upload-artifact@v3
            with:
              name: valid-proxies
              path: valid_proxies.txt
    

    to this

    - name: Commit and push updated proxies
            run: |
              git config user.name "github-actions"
              git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
              git add valid_proxies.txt
              git commit -m "Update valid proxies file"
              git push
    

  2. 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.

    jobs:
      update-proxies:
        runs-on: ubuntu-latest
    
        permissions:
          contents: write
    
        steps:
    
          - uses: actions/checkout@v4
    
          [... steps that eventually update valid_proxies.txt]
    
          - name: Setup GitHub actions bot identity
            run: |
              git config user.name 'github-actions[bot]'
              git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
    
          - name: commit changes, if any
            run: |
              git add valid_proxies.txt
              if git commit -m'update valid_proxies.txt'; then git push; fi
    

    Additional notes

    • permissions: contents: write is required if your repo has the protection settings currently recommended.
    • That weird e-mail address is the bot’s official account. If you use it, you’ll see the Octocat icon next to the bot commits: Octocat icon
    • If you know the proxies file always changes, you can just have git commit and then git push, but with that if statement around the git commit, you won’t get an error if the file stays unchanged on a given run.
    • Notice I used 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

          - uses: stefanzweifel/git-auto-commit-action@v5
    

    or maybe

          - uses: stefanzweifel/git-auto-commit-action@v5
            with:
              commit_message: update valid_proxies.txt
              file_pattern: valid_proxies.txt
    

    which takes care of everything.

    See https://github.com/stefanzweifel/git-auto-commit-action

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search