Skip to content
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

Update github actions #1443

Merged
merged 1 commit into from
Nov 1, 2022

Conversation

ppigazzini
Copy link
Collaborator

@ppigazzini ppigazzini commented Oct 31, 2022

Split in server and worker workflows.
Set up the server workflow with the SW versions used on PROD.
Set up the worker workflows to test on Linux with few python versions and on Windows msys2.

See:
https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
https://github.com/marketplace/actions/setup-msys2

@ppigazzini ppigazzini added enhancement update code change to account external change (Stockfish, book etc.) labels Oct 31, 2022
@ppigazzini ppigazzini force-pushed the actions_update branch 15 times, most recently from d2877f3 to cc75406 Compare November 1, 2022 02:07
Split in server and worker workflows.
Set up the server workflow with the SW versions used on PROD.
Set up the worker workflows to test on Linux with few python versions and on Windows msys2.

See:
https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
https://github.com/marketplace/actions/setup-msys2
@ppigazzini ppigazzini merged commit d7172fc into official-stockfish:master Nov 1, 2022
@ppigazzini ppigazzini deleted the actions_update branch November 1, 2022 10:34
@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

Would it be possible to test the worker also on MacOSX? There is some Mac specific code in the worker and it would be nice to be able to test it.

@ppigazzini
Copy link
Collaborator Author

That was my intention but I got an error when adding MacOSX in the workflow matrix.

@ppigazzini
Copy link
Collaborator Author

@Disservin
Copy link
Member

What error ? We have macos in the stockfish CI if you are interested take a look there only the avx2 compile doesn’t work for macOS ci runner

@ppigazzini
Copy link
Collaborator Author

My first implementation had python 3.5 too in the matrix (now dropped because I would like to switch to pathlib), the macos action works now for python 3.6-3.11
https://github.com/ppigazzini/fishtest/actions/runs/3445037852

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

I got the error when using only one workflow for linux and macos, it seems that we are hitting a rate limit for url: https://api.github.com/repos/official-stockfish/books/git/trees/master

https://github.com/ppigazzini/fishtest/actions/runs/3445092768/jobs/5748408359

test_worker_script_with_no_args (test_worker.workerTest.test_worker_script_with_no_args) ... ok

======================================================================
ERROR: test_item_download (test_worker.workerTest.test_item_download)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/fishtest/fishtest/worker/games.py", line 146, in requests_get
    result.raise_for_status()  # also catch return codes >= 400
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/runner/work/fishtest/fishtest/worker/.eggs/requests-2.28.1-py3.11.egg/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
uests.exceptions.HTTPError: 403 Client Error: rate limit exceeded for url: https://api.github.com/repos/official-stockfish/books/git/trees/master

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/runner/work/fishtest/fishtest/worker/test_worker.py", line 22, in test_item_download
    games.download_from_github("README.md", ".")
  File "/Users/runner/work/fishtest/fishtest/worker/games.py", line 396, in download_from_github
    tree = requests_get(
           ^^^^^^^^^^^^^
  File "/Users/runner/work/fishtest/fishtest/worker/games.py", line 154, in requests_get
    raise WorkerException("Get request to {} failed".format(remote), e=e)
games.WorkerException: Get request to https://api.github.com/repos/official-stockfish/books/git/trees/master failed

----------------------------------------------------------------------
Ran 6 tests in 20.487s

@ppigazzini
Copy link
Collaborator Author

I don't understand why only the macos workflow is hitting that rate limit...

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

The issue comes from the way how GitHub counts requests for rate limit. For unauthorized requests, it limits by IP. All macOS VMs have the same IP address because of infrastructure. GitHub complains about rate limit regardless of the source of request because GA workflow can be used to spam API too.

actions/runner-images#602

@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

Perhaps we can fake the rate limit request during testing?

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

The macos workflow still fails when using the github token, even with only one python version.
https://dev.to/github/the-githubtoken-in-github-actions-how-it-works-change-permissions-customizations-3cgp

      - name: Run worker tests
        run: |
          ./test_worker.sh
        env:
          GITHUB_TOKEN: ${{ github.token }}
          # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

@ppigazzini Do you have the link of that action?

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

https://github.com/ppigazzini/fishtest/actions/

I wonder why we are hitting the link https://api.github.com/repos/official-stockfish/books/git/trees/master with this code:

    def test_item_download(self):
        try:
            games.download_from_github("README.md", ".")
            self.assertTrue(os.path.exists(os.path.join(".", "README.md")))
        except KeyError:
            pass

EDIT_000: because the function is in truth def download_from_books_repo():

REPO_URL = "https://github.com/official-stockfish/books"

def download_from_github(item, testing_dir):
    """Download item from FishCooking to testing_dir"""
    tree = requests_get(
        github_api(REPO_URL) + "/git/trees/master", timeout=HTTP_TIMEOUT
    ).json()
    for blob in tree["tree"]:
        if blob["path"] == item:
            print("Downloading {} ...".format(item))
            blob_json = requests_get(blob["url"], timeout=HTTP_TIMEOUT).json()
            with open(os.path.join(testing_dir, item), "wb+") as f:
                f.write(b64decode(blob_json["content"]))
            break
    else:
        raise WorkerException("Item {} not found".format(item))

@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

It is strange that the github token does not work since it is officially supported.

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

Doubts:

  • we are hitting an external repo

the token's permissions are limited to the repository that contains your workflow

  • we are using run:

EDIT_000: switching to the fishtest repo that runs the workflow (with the github token passed to the env) failed too...

    def test_item_download(self):
        try:
            games.REPO_URL = "https://github.com/ppigazzini/fishtest"
            games.download_from_github("README.md", ".")
            self.assertTrue(os.path.exists(os.path.join(".", "README.md")))
        except KeyError:
            pass
ERROR: test_item_download (test_worker.workerTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/fishtest/fishtest/worker/games.py", line 146, in requests_get
    result.raise_for_status()  # also catch return codes >= 400
  File "/Users/runner/work/fishtest/fishtest/worker/.eggs/requests-2.28.1-py3.7.egg/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: rate limit exceeded for url: https://api.github.com/repos/ppigazzini/fishtest/git/trees/masteres/master failed

image

@ppigazzini
Copy link
Collaborator Author

ppigazzini commented Nov 11, 2022

This failed randomly too:

      - name: Run worker tests
        run: |
          cd worker && python setup.py test
        env:
          #GITHUB_TOKEN: ${{ github.token }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

EDIT_000: failed setting a high level env too.

name: CI worker posix

on: [push, pull_request, workflow_dispatch]
env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

Maybe we can download things using raw.githubusercontent.com ? I think this is not affected by api credits.

EDIT: I do not think there is a risk getting outdated content in this way.

@vdbergh
Copy link
Contributor

vdbergh commented Nov 11, 2022

I made a PR. Have a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement update code change to account external change (Stockfish, book etc.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants