From 868b48a5af922b2a3205309e322f90b47aeaaa88 Mon Sep 17 00:00:00 2001 From: Matt Haggard Date: Fri, 11 Dec 2020 17:04:30 -0500 Subject: [PATCH] GitHub actions (#1744) * Add GitHub actions * Workflow typo * Workflow typo * Use GITHUB_TOKEN in build if available --- .github/workflows/test.yml | 16 ++++++++++++++++ package_scanner.nim | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6df8ab5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,16 @@ +on: + pull_request: + push: + +jobs: + default: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: iffy/install-nim@v3 + with: + version: stable + - run: nim c -d:ssl -r package_scanner.nim + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - run: node ./validate_json.js diff --git a/package_scanner.nim b/package_scanner.nim index 78c4f0b..7756527 100644 --- a/package_scanner.nim +++ b/package_scanner.nim @@ -54,12 +54,16 @@ proc canFetchNimbleRepository(name: string, urlJson: JsonNode): bool = # nimble file in it result = true var url: string + var client = newHttpClient(timeout=100000) + defer: client.close() if not urlJson.isNil: url = urlJson.str - + if url.startsWith("https://github.com"): + if existsEnv("GITHUB_TOKEN"): + client.headers = newHttpHeaders({"authorization": "Bearer " & getEnv("GITHUB_TOKEN")}) try: - discard getContent(url, timeout=10000) + discard client.getContent(url) except HttpRequestError, TimeoutError: echo "W: ", name, ": unable to fetch repo ", url, " ", getCurrentExceptionMsg()