Skip to content

Commit

Permalink
Like this?
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Nov 22, 2024
1 parent 3f9057c commit eaed363
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 40 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ jobs:
id: get_last_id
run: |
pip install requests
python utils/get.py ${{ secrets.GITHUB_TOKEN }}
# echo "last_run_id=$((${{ github.run_id }} - 1))" >> $GITHUB_OUTPUT
# - name: Download last run commit hashes
# continue-on-error: true
# uses: actions/download-artifact@v4
# with:
# name: commit-hashes.txt
# path: previous-run-hashes.txt
# github-token: ${{ secrets.GITHUB_TOKEN }}
# # Previous run
# run-id: ${{ job.get_last_id.last_run_id }}
python utils/get.py >> $GITHUB_OUTPUT
- name: Download last run commit hashes
needs: get_last_id
if: ${{ fromJSON(job.get_last_id.HAS_RUN_ID) }}
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: commit-hashes.txt
path: previous-run-hashes.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
# Previous run
run-id: ${{ job.get_last_id.LAST_RUN_ID }}
# - name: Check if run needed
# run: |
# if [ ! -f previous-run-hashes.txt ]; then
Expand Down
37 changes: 8 additions & 29 deletions get.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import requests
import subprocess
import pathlib
import sys


def get_commit_hash(dir: pathlib.Path) -> str | None:
try:
return subprocess.check_output(
["git", "rev-parse", "HEAD"], cwd=str(dir)
).decode()
except subprocess.CalledProcessError:
return None


def previous_run_hashes(token: str) -> str | None:
def previous_run_id() -> str | None:
req = requests.get(
"https://api.github.com/repos/rapidsai/dask-upstream-testing/actions/artifacts",
headers={
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
"Authorization": token,
},
params={"name": "commit-hashes.txt", "page": 1, "per_page": 1},
)
Expand All @@ -29,24 +16,16 @@ def previous_run_hashes(token: str) -> str | None:
artifacts = req.json()["artifacts"]
try:
(artifact,) = artifacts
url = artifact["archive_download_url"]
url_req = requests.get(
url, headers={"X-GitHub-Api-Version": "2022-11-28", "Authorization": token}
)
if url_req.status_code != 302:
print("Failed", url_req.text)
loc = url_req.headers["Location"]
print(loc)
archive = requests.get(
loc, headers={"X-GitHub-Api-Version": "2022-11-28", "Authorization": token}
)
print(archive.status_code)
print(archive.text)
return artifact["workflow_run"]["id"]
except ValueError:
# Didn't get exactly one artifact, assume we must rebuild
return None


if __name__ == "__main__":
TOKEN = sys.argv[1]
previous_run_hashes(TOKEN)
run_id = previous_run_id()
if run_id is not None:
print(f"LAST_RUN_ID={run_id}")
print("HAS_RUN_ID=true")
else:
print("HAS_RUN_ID=false")

0 comments on commit eaed363

Please sign in to comment.