Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,11 @@ Placeholder Definition
Travis and Appveyor, this is the hash of an autogenerated
merge commit.
``{commit}`` The hash of the original commit that triggered the build
or that was tagged for the release. For GitHub Actions
and all non-pull request builds, this is always the same
as ``{build_commit}``. For pull request builds on
Appveyor, this is the head of the PR branch. For pull
request builds on Travis, this is ``UNK``, as the API does
not expose the original commit.
or that was tagged for the release. For pull request
builds, this is the head of the PR branch, or ``UNK`` if
it cannot be determined. For other builds (along with PR
builds on GitHub Actions), this is always the same as
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confused: so this PR doesn't provide solution for deducing the corresponding commit for GH actions PR runs? For GH actions, like even in this PR we might have both "pull_request" (where commit != build_commit) and "push" (where commit == build_commit AFAIK) runs.

Or it is just a matter of me not grasping it from the above description, that the comment above for "PR push builds" while "pull_request" builds will have different commit and build_commit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PR builds in GitHub Actions, {commit} always equals {build_commit}, as the API reports the PR head commit as the commit being built (despite actually operating on a merge commit).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR my run on -inception: Running fetch for current state of this PR where pull_request run has logged

HEAD is now at 03f35eb Merge c30b87e into 52c92e0

so the {commit} is c30b87e and corresponding {build_commit} for a PR is a long version of 03f35eb

which seems to be available within workflow under `GITHUB_SHA` env var and logged
$> grep -2 03f35eb /tmp/pull.log             
2021-06-01T16:26:05.9877449Z ##[endgroup]
2021-06-01T16:26:05.9878299Z ##[group]Fetching the repository
2021-06-01T16:26:05.9880965Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +03f35ebbd696894fe61c2fff46217bff60019db8:refs/remotes/pull/68/merge
2021-06-01T16:26:06.7655812Z remote: Enumerating objects: 415, done.        
2021-06-01T16:26:06.7657174Z remote: Counting objects:   0% (1/415)        
--
2021-06-01T16:26:06.9301459Z  * [new tag]         0.1.0                                    -> 0.1.0
2021-06-01T16:26:06.9302504Z  * [new tag]         0.2.0                                    -> 0.2.0
2021-06-01T16:26:06.9303825Z  * [new ref]         03f35ebbd696894fe61c2fff46217bff60019db8 -> pull/68/merge
2021-06-01T16:26:06.9324429Z ##[endgroup]
2021-06-01T16:26:06.9325540Z ##[group]Determining the checkout info
--
2021-06-01T16:26:06.9418560Z Turn off this advice by setting config variable advice.detachedHead to false
2021-06-01T16:26:06.9419097Z 
2021-06-01T16:26:06.9419965Z HEAD is now at 03f35eb Merge c30b87e74a47cd360306f0674f793b14c79843da into 52c92e0b0cc683e53ebde25f7ec32cd98434e2ba
2021-06-01T16:26:06.9421009Z ##[endgroup]
2021-06-01T16:26:06.9468912Z [command]/usr/bin/git log -1 --format='%H'
2021-06-01T16:26:06.9503665Z '03f35ebbd696894fe61c2fff46217bff60019db8'
2021-06-01T16:26:06.9662780Z ##[group]Run actions/setup-python@v2
2021-06-01T16:26:06.9663354Z with:
--
2021-06-01T16:26:16.7066375Z py create: /home/runner/work/tinuous/tinuous/.tox/py
2021-06-01T16:26:17.0404949Z py installdeps: pytest~=6.0, pytest-cov~=2.0
2021-06-01T16:26:20.7202989Z py inst: /home/runner/work/tinuous/tinuous/.tox/.tmp/package/1/tinuous-0.2.0+25.g03f35eb.tar.gz
2021-06-01T16:26:32.4749600Z py installed: attrs==21.2.0,certifi==2021.5.30,cffi==1.14.5,chardet==4.0.0,click==8.0.1,click-loglevel==0.3.0,coverage==5.5,Deprecated==1.2.12,idna==2.10,in-place==0.5.0,iniconfig==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pycparser==2.20,pydantic==1.8.2,PyGithub==1.55,PyJWT==2.1.0,PyNaCl==1.4.0,pyparsing==2.4.7,pytest==6.2.4,pytest-cov==2.12.0,python-dateutil==2.8.1,python-dotenv==0.17.1,PyYAML==5.4.1,requests==2.25.1,six==1.16.0,tinuous @ file:///home/runner/work/tinuous/tinuous/.tox/.tmp/package/1/tinuous-0.2.0%2B25.g03f35eb.tar.gz,toml==0.10.2,typing-extensions==3.10.0.0,urllib3==1.26.5,wrapt==1.12.1
2021-06-01T16:26:32.4766477Z py run-test-pre: PYTHONHASHSEED='3615710078'
2021-06-01T16:26:32.4767989Z py run-test: commands[0] | tinuous --help
--
2021-06-01T16:26:33.8157549Z       -> GITHUB_REPOSITORY: con/tinuous
2021-06-01T16:26:33.8158362Z       -> GITHUB_RUN_ID:     896736691
2021-06-01T16:26:33.8159272Z       -> GITHUB_SHA:        03f35ebbd696894fe61c2fff46217bff60019db8
2021-06-01T16:26:33.8160217Z       -> GITHUB_WORKFLOW:   Test
2021-06-01T16:26:33.8348887Z     project root: .
using this tuned up config for inception
repo: con/tinuous
vars:
  path_prefix: 'logs/{year}/{month}/{day}/{type}/{type_id}/{commit[:8]}-{build_commit[:8]}/{ci}'
ci:
  github:
    path: '{path_prefix}/{wf_name}/{number}/'
    workflows:
      - test.yml
  travis:
    path: '{path_prefix}/{number}/{job}.txt'
  appveyor:
    path: '{path_prefix}/{number}/{job}.txt'
    accountName: yarikoptic
since: 2021-06-01T00:00:00Z
types: [cron, pr, push]
I got following output printed by tinuous
(git)lena:~/proj/tinuous-inception[master]git
$> ( source $PWD.secrets; tinuous fetch )                       
2021-06-01T13:59:00-0400 [INFO    ] tinuous Fetching resources from github
2021-06-01T13:59:00-0400 [INFO    ] tinuous Fetching runs newer than 2021-05-28 19:53:08+00:00
2021-06-01T13:59:00-0400 [INFO    ] tinuous Fetching runs for workflow .github/workflows/test.yml (Test)
2021-06-01T13:59:01-0400 [INFO    ] tinuous Found run 143
2021-06-01T13:59:01-0400 [INFO    ] tinuous Downloading logs for test.yml (Test) #143 to logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143
2021-06-01T13:59:02-0400 [INFO    ] tinuous Found run 142
2021-06-01T13:59:02-0400 [INFO    ] tinuous Downloading logs for test.yml (Test) #142 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142
2021-06-01T13:59:03-0400 [INFO    ] tinuous Found run 141
2021-06-01T13:59:03-0400 [INFO    ] tinuous Downloading logs for test.yml (Test) #141 to logs/2021/06/01/push/master/52c92e0b-52c92e0b/github/Test/141
2021-06-01T13:59:04-0400 [INFO    ] tinuous Fetching resources from travis
2021-06-01T13:59:04-0400 [INFO    ] tinuous Fetching builds newer than 2021-05-28 19:53:39+00:00
2021-06-01T13:59:05-0400 [INFO    ] tinuous Found build 127
2021-06-01T13:59:06-0400 [INFO    ] tinuous Downloading logs for job 127.1 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/1.txt
2021-06-01T13:59:07-0400 [INFO    ] tinuous Downloading logs for job 127.2 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/2.txt
2021-06-01T13:59:07-0400 [INFO    ] tinuous Downloading logs for job 127.3 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/3.txt
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 127.4 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/4.txt
2021-06-01T13:59:08-0400 [INFO    ] tinuous Found build 126
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 126.1 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/1.txt
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 126.2 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/2.txt
2021-06-01T13:59:09-0400 [INFO    ] tinuous Downloading logs for job 126.3 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/3.txt
2021-06-01T13:59:09-0400 [INFO    ] tinuous Downloading logs for job 126.4 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/4.txt
2021-06-01T13:59:10-0400 [INFO    ] tinuous Found build 125
2021-06-01T13:59:10-0400 [INFO    ] tinuous Downloading logs for job 125.1 to logs/2021/06/01/push/master/52c92e0b-52c92e0b/travis/125/1.txt
2021-06-01T13:59:10-0400 [INFO    ] tinuous Downloading logs for job 125.2 to logs/2021/06/01/push/master/52c92e0b-52c92e0b/travis/125/2.txt
2021-06-01T13:59:11-0400 [INFO    ] tinuous Downloading logs for job 125.3 to logs/2021/06/01/push/master/52c92e0b-52c92e0b/travis/125/3.txt
2021-06-01T13:59:11-0400 [INFO    ] tinuous Downloading logs for job 125.4 to logs/2021/06/01/push/master/52c92e0b-52c92e0b/travis/125/4.txt
2021-06-01T13:59:11-0400 [INFO    ] tinuous Fetching resources from appveyor
2021-06-01T13:59:11-0400 [INFO    ] tinuous Fetching runs newer than 2021-05-28 19:53:09.355234+00:00
2021-06-01T13:59:12-0400 [INFO    ] tinuous Found build 132
2021-06-01T13:59:13-0400 [INFO    ] tinuous Downloading logs for build 132, job 8ka4r2bfy28kipyr to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/8ka4r2bfy28kipyr.txt
2021-06-01T13:59:14-0400 [INFO    ] tinuous Downloading logs for build 132, job cngwpof9ihphuvyt to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/cngwpof9ihphuvyt.txt
2021-06-01T13:59:14-0400 [INFO    ] tinuous Downloading logs for build 132, job oc8g6obu4gi6xxkb to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/oc8g6obu4gi6xxkb.txt
2021-06-01T13:59:15-0400 [INFO    ] tinuous Downloading logs for build 132, job xc522ci6wtm7esb9 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/xc522ci6wtm7esb9.txt
2021-06-01T13:59:15-0400 [INFO    ] tinuous Found build 131
2021-06-01T13:59:16-0400 [INFO    ] tinuous Downloading logs for build 131, job iq45xnsbd5nx6msc to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/iq45xnsbd5nx6msc.txt
2021-06-01T13:59:16-0400 [INFO    ] tinuous Downloading logs for build 131, job j84iy002fq4jbw8b to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/j84iy002fq4jbw8b.txt
2021-06-01T13:59:17-0400 [INFO    ] tinuous Downloading logs for build 131, job cr7b7ego0j9o0w1f to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/cr7b7ego0j9o0w1f.txt
2021-06-01T13:59:18-0400 [INFO    ] tinuous Downloading logs for build 131, job 89poa9je5tc6kjr9 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/89poa9je5tc6kjr9.txt
2021-06-01T13:59:18-0400 [INFO    ] tinuous Found build 130
2021-06-01T13:59:19-0400 [INFO    ] tinuous Downloading logs for build 130, job 1raf7y7cf7bebdhd to logs/2021/06/01/push/master/52c92e0b-52c92e0b/appveyor/130/1raf7y7cf7bebdhd.txt
2021-06-01T13:59:19-0400 [INFO    ] tinuous Downloading logs for build 130, job kce4c7eh07gbw2ah to logs/2021/06/01/push/master/52c92e0b-52c92e0b/appveyor/130/kce4c7eh07gbw2ah.txt
2021-06-01T13:59:20-0400 [INFO    ] tinuous Downloading logs for build 130, job ttyci7iyof3ci4hn to logs/2021/06/01/push/master/52c92e0b-52c92e0b/appveyor/130/ttyci7iyof3ci4hn.txt
2021-06-01T13:59:21-0400 [INFO    ] tinuous Downloading logs for build 130, job w18avxp6vo26rtor to logs/2021/06/01/push/master/52c92e0b-52c92e0b/appveyor/130/w18avxp6vo26rtor.txt
we indeed got correct "matching" c30b87e-c30b87e7 for push builds across all (good) + the one for github PR (not so good)
$> xsel -o | grep c30b87e7-c30
2021-06-01T13:59:01-0400 [INFO    ] tinuous Downloading logs for test.yml (Test) #143 to logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143
2021-06-01T13:59:02-0400 [INFO    ] tinuous Downloading logs for test.yml (Test) #142 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 126.1 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/1.txt
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 126.2 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/2.txt
2021-06-01T13:59:09-0400 [INFO    ] tinuous Downloading logs for job 126.3 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/3.txt
2021-06-01T13:59:09-0400 [INFO    ] tinuous Downloading logs for job 126.4 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/travis/126/4.txt
2021-06-01T13:59:16-0400 [INFO    ] tinuous Downloading logs for build 131, job iq45xnsbd5nx6msc to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/iq45xnsbd5nx6msc.txt
2021-06-01T13:59:16-0400 [INFO    ] tinuous Downloading logs for build 131, job j84iy002fq4jbw8b to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/j84iy002fq4jbw8b.txt
2021-06-01T13:59:17-0400 [INFO    ] tinuous Downloading logs for build 131, job cr7b7ego0j9o0w1f to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/cr7b7ego0j9o0w1f.txt
2021-06-01T13:59:18-0400 [INFO    ] tinuous Downloading logs for build 131, job 89poa9je5tc6kjr9 to logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/appveyor/131/89poa9je5tc6kjr9.txt
and travis and appveyor correctly had c30b87e-03f35ebb (`{commit}-{build-commit}`) for PRs
$> xsel -o | grep c30b87e7-[^c]  
2021-06-01T13:59:06-0400 [INFO    ] tinuous Downloading logs for job 127.1 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/1.txt
2021-06-01T13:59:07-0400 [INFO    ] tinuous Downloading logs for job 127.2 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/2.txt
2021-06-01T13:59:07-0400 [INFO    ] tinuous Downloading logs for job 127.3 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/3.txt
2021-06-01T13:59:08-0400 [INFO    ] tinuous Downloading logs for job 127.4 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/travis/127/4.txt
2021-06-01T13:59:13-0400 [INFO    ] tinuous Downloading logs for build 132, job 8ka4r2bfy28kipyr to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/8ka4r2bfy28kipyr.txt
2021-06-01T13:59:14-0400 [INFO    ] tinuous Downloading logs for build 132, job cngwpof9ihphuvyt to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/cngwpof9ihphuvyt.txt
2021-06-01T13:59:14-0400 [INFO    ] tinuous Downloading logs for build 132, job oc8g6obu4gi6xxkb to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/oc8g6obu4gi6xxkb.txt
2021-06-01T13:59:15-0400 [INFO    ] tinuous Downloading logs for build 132, job xc522ci6wtm7esb9 to logs/2021/06/01/pr/68/c30b87e7-03f35ebb/appveyor/132/xc522ci6wtm7esb9.txt

github actions got two separate logs (for PR and branch) logs and indeed {build_commit} was corresponding to the actual {commit}:

$> md5sum logs/2021/06/01/*/*6[78]/*-*/github/Test/*/1_*       
a7dd2fa04a10aab7073134bbe882ed44  logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt
fcda200d4a72e2ff4a10b89356385304  logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test.txt
d4b248ea53ef5633f0085dbff058c636  logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142/1_test (3.8, py).txt
ce25bcbea54edb570beaa7a6f8344bbb  logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142/1_test.txt
and actual `{build_comit}` (merge) was logged
$> grep 03f35ebb logs/2021/06/01/*/*6[78]/*-*/github/Test/*/*  
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt:2021-06-01T16:26:05.9880965Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +03f35ebbd696894fe61c2fff46217bff60019db8:refs/remotes/pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt:2021-06-01T16:26:06.9303825Z  * [new ref]         03f35ebbd696894fe61c2fff46217bff60019db8 -> pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt:2021-06-01T16:26:06.9503665Z '03f35ebbd696894fe61c2fff46217bff60019db8'
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt:2021-06-01T16:26:33.8159272Z       -> GITHUB_SHA:        03f35ebbd696894fe61c2fff46217bff60019db8
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/2_test (3.9, py).txt:2021-06-01T16:26:07.4848839Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +03f35ebbd696894fe61c2fff46217bff60019db8:refs/remotes/pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/2_test (3.9, py).txt:2021-06-01T16:26:07.5482896Z  * [new ref]         03f35ebbd696894fe61c2fff46217bff60019db8 -> pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/2_test (3.9, py).txt:2021-06-01T16:26:07.5507755Z '03f35ebbd696894fe61c2fff46217bff60019db8'
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/2_test (3.9, py).txt:2021-06-01T16:26:38.0549362Z       -> GITHUB_SHA:        03f35ebbd696894fe61c2fff46217bff60019db8
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/3_test (3.8, lint).txt:2021-06-01T16:26:04.5885839Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +03f35ebbd696894fe61c2fff46217bff60019db8:refs/remotes/pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/3_test (3.8, lint).txt:2021-06-01T16:26:04.6136425Z  * [new ref]         03f35ebbd696894fe61c2fff46217bff60019db8 -> pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/3_test (3.8, lint).txt:2021-06-01T16:26:04.6155411Z '03f35ebbd696894fe61c2fff46217bff60019db8'
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/4_test (3.8, typing).txt:2021-06-01T16:26:07.9074233Z [command]/usr/bin/git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +03f35ebbd696894fe61c2fff46217bff60019db8:refs/remotes/pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/4_test (3.8, typing).txt:2021-06-01T16:26:07.9353344Z  * [new ref]         03f35ebbd696894fe61c2fff46217bff60019db8 -> pull/68/merge
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/4_test (3.8, typing).txt:2021-06-01T16:26:07.9444015Z '03f35ebbd696894fe61c2fff46217bff60019db8'

With the observation of consistently logged GITHUB_SHA we could use that one for the case where commit == build_commit and take it instead for the build_commit if differs. Could we do that to overcome github deficiency?

here is where I observe it being printed across all runs
$> grep GITHUB_SHA logs/2021/06/01/*/*/*-*/github/Test/*/* 
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/1_test (3.8, py).txt:2021-06-01T16:26:33.8159272Z       -> GITHUB_SHA:        03f35ebbd696894fe61c2fff46217bff60019db8
logs/2021/06/01/pr/68/c30b87e7-c30b87e7/github/Test/143/2_test (3.9, py).txt:2021-06-01T16:26:38.0549362Z       -> GITHUB_SHA:        03f35ebbd696894fe61c2fff46217bff60019db8
logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142/1_test (3.8, py).txt:2021-06-01T16:25:50.5463386Z       -> GITHUB_SHA:        c30b87e74a47cd360306f0674f793b14c79843da
logs/2021/06/01/push/gh-67/c30b87e7-c30b87e7/github/Test/142/2_test (3.9, py).txt:2021-06-01T16:25:55.2605208Z       -> GITHUB_SHA:        c30b87e74a47cd360306f0674f793b14c79843da
logs/2021/06/01/push/master/52c92e0b-52c92e0b/github/Test/141/1_test (3.8, py).txt:2021-06-01T15:22:09.3739855Z       -> GITHUB_SHA:        52c92e0b0cc683e53ebde25f7ec32cd98434e2ba
logs/2021/06/01/push/master/52c92e0b-52c92e0b/github/Test/141/2_test (3.9, py).txt:2021-06-01T15:22:19.2035941Z       -> GITHUB_SHA:        52c92e0b0cc683e53ebde25f7ec32cd98434e2ba

so it seems to be nicely consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GITHUB_SHA line is part of the output from the Codecov action. It won't be present on workflows that don't use Codecov.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d'oh -- right. Could we (ab)use

HEAD is now at 03f35eb Merge c30b8...

as

HEAD is now at 03f35eb Merge {commit} .*

line then may be, even though we would not get a full hexsha out of it (well, could be chased with a follow up search for a string starting from that since it seems to be right there:

2021-06-01T16:26:06.9419965Z HEAD is now at 03f35eb Merge c30b87e74a47cd360306f0674f793b14c79843da into 52c92e0b0cc683e53ebde25f7ec32cd98434e2ba
2021-06-01T16:26:06.9421009Z ##[endgroup]
2021-06-01T16:26:06.9468912Z [command]/usr/bin/git log -1 --format='%H'
2021-06-01T16:26:06.9503665Z '03f35ebbd696894fe61c2fff46217bff60019db8'

I just do not want us to give up since then we can not nicely and easily group all runs across CIs and disambiguate between PR runs against different bases (e.g. if base is changed after PR is initiated) :-/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yarikoptic Maybe. It'd require downloading logs before knowing where to place them, and it'd fail for workflows that don't perform a checkout.

and you did file a support request IIRC with github but no action was taken yet, right?
I also dislike "parse the logs" solution but poking around API did not find yet anything which could help -- there is no endpoint by any chance to query env variables for the run, is there (I did not find any)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not file a support request about this. Are you thinking of the support request I filed with Travis to include the PR head in their API?

I do not believe the GitHub API has an endpoint for workflow run variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I mixed up with that one indeed! Could you please file an issue with github so we possibly see if there is a bright future whenever it would be supported? I also wonder why they do not anyhow expose environment variables (e.g. even without secrets) -- that could have given us remedy

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support issue filed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's hold breath for a little bit. I think we can proceed with this PR since for many usecases we can already have it working nicely, filed a dedicated #69 for the github actions.

``{build_commit}``.
``{number}`` The run number of the workflow run (GitHub) or the build
number (Travis and Appveyor) [1]_
``{status}`` The success status of the workflow run (GitHub) or job
Expand Down Expand Up @@ -389,6 +388,10 @@ A Travis API access token can be acquired as follows:

- Run ``travis token --com`` to retrieve the API access token.

The Travis integration also requires a GitHub OAuth token in order to look up
information on pull requests that the Travis API does not report; this token
must be specified in the same way as for the GitHub integration.

Appveyor
~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions src/tinuous/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def fetch(cfg: Config, state: str, sanitize_secrets: bool) -> None:
except FileNotFoundError:
since_stamps = {}
# Fetch tokens early in order to catch failures early:
tokens: Dict[str, str] = {}
tokens: Dict[str, Dict[str, str]] = {}
for name, cicfg in cfg.ci.items():
tokens[name] = cicfg.get_auth_token()
tokens[name] = cicfg.get_auth_tokens()
if cfg.datalad.enabled:
try:
from datalad.api import Dataset
Expand All @@ -100,7 +100,7 @@ def fetch(cfg: Config, state: str, sanitize_secrets: bool) -> None:
since = datetime.fromisoformat(since_stamps[name])
except KeyError:
since = cfg.since
ci = cicfg.get_system(repo=cfg.repo, since=since, token=tokens[name])
ci = cicfg.get_system(repo=cfg.repo, since=since, tokens=tokens[name])
for obj in ci.get_build_assets(cfg.types, artifacts=get_artifacts):
if isinstance(obj, BuildLog):
path = obj.expand_path(cicfg.path, cfg.vars)
Expand Down
4 changes: 2 additions & 2 deletions src/tinuous/appveyor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class Appveyor(CISystem):
projectSlug: Optional[str]

@staticmethod
def get_auth_token() -> str:
def get_auth_tokens() -> Dict[str, str]:
token = os.environ.get("APPVEYOR_TOKEN")
if not token:
raise RuntimeError(
"Appveyor API key not set. Set via APPVEYOR_TOKEN environment"
" variable."
)
return token
return {"appveyor": token}

@property
def repo_slug(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CISystem(ABC, BaseModel):

@staticmethod
@abstractmethod
def get_auth_token() -> str:
def get_auth_tokens() -> Dict[str, str]:
... # pragma: no cover

@abstractmethod
Expand Down
35 changes: 21 additions & 14 deletions src/tinuous/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ class CIConfig(NoExtraModel, ABC):

@staticmethod
@abstractmethod
def get_auth_token() -> str:
def get_auth_tokens() -> Dict[str, str]:
... # pragma: no cover

@abstractmethod
def get_system(self, repo: str, since: datetime, token: str) -> CISystem:
def get_system(
self, repo: str, since: datetime, tokens: Dict[str, str]
) -> CISystem:
... # pragma: no cover


Expand All @@ -36,28 +38,31 @@ class GitHubConfig(CIConfig):
workflows: Optional[List[str]] = None

@staticmethod
def get_auth_token() -> str:
return GitHubActions.get_auth_token()
def get_auth_tokens() -> Dict[str, str]:
return GitHubActions.get_auth_tokens()

def get_system(self, repo: str, since: datetime, token: str) -> GitHubActions:
def get_system(
self, repo: str, since: datetime, tokens: Dict[str, str]
) -> GitHubActions:
return GitHubActions(
repo=repo,
since=since,
token=token,
token=tokens["github"],
workflows=self.workflows,
)


class TravisConfig(CIConfig):
@staticmethod
def get_auth_token() -> str:
return Travis.get_auth_token()
def get_auth_tokens() -> Dict[str, str]:
return Travis.get_auth_tokens()

def get_system(self, repo: str, since: datetime, token: str) -> Travis:
def get_system(self, repo: str, since: datetime, tokens: Dict[str, str]) -> Travis:
return Travis(
repo=repo,
since=since,
token=token,
token=tokens["travis"],
gh_token=tokens["github"],
)


Expand All @@ -66,14 +71,16 @@ class AppveyorConfig(CIConfig):
projectSlug: Optional[str] = None

@staticmethod
def get_auth_token() -> str:
return Appveyor.get_auth_token()
def get_auth_tokens() -> Dict[str, str]:
return Appveyor.get_auth_tokens()

def get_system(self, repo: str, since: datetime, token: str) -> Appveyor:
def get_system(
self, repo: str, since: datetime, tokens: Dict[str, str]
) -> Appveyor:
return Appveyor(
repo=repo,
since=since,
token=token,
token=tokens["appveyor"],
accountName=self.accountName,
projectSlug=self.projectSlug,
)
Expand Down
27 changes: 10 additions & 17 deletions src/tinuous/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path
import re
from shutil import rmtree
import subprocess
import tempfile
from typing import Dict, Iterator, List, Optional, Tuple
from zipfile import ZipFile
Expand All @@ -18,29 +17,23 @@
import requests

from .base import APIClient, Artifact, BuildAsset, BuildLog, CISystem, EventType
from .util import ensure_aware, expand_template, iterfiles, log, stream_to_file
from .util import (
ensure_aware,
expand_template,
get_github_token,
iterfiles,
log,
stream_to_file,
)


class GitHubActions(CISystem):
workflows: Optional[List[str]] = None
hash2pr: Dict[str, str] = Field(default_factory=dict)

@staticmethod
def get_auth_token() -> str:
token = os.environ.get("GITHUB_TOKEN")
if not token:
r = subprocess.run(
["git", "config", "hub.oauthtoken"],
stdout=subprocess.PIPE,
universal_newlines=True,
)
if r.returncode != 0 or not r.stdout.strip():
raise RuntimeError(
"GitHub OAuth token not set. Set via GITHUB_TOKEN"
" environment variable or hub.oauthtoken Git config option."
)
token = r.stdout.strip()
return token
def get_auth_tokens() -> Dict[str, str]:
return {"github": get_github_token()}

@cached_property
def client(self) -> Github:
Expand Down
63 changes: 45 additions & 18 deletions src/tinuous/travis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
from urllib.parse import quote

from dateutil.parser import isoparse
from github import Github
from github.Repository import Repository

from .base import APIClient, BuildAsset, BuildLog, CISystem, EventType
from .util import log, removeprefix, stream_to_file
from .util import get_github_token, log, removeprefix, stream_to_file


class Travis(CISystem):
gh_token: str

@staticmethod
def get_auth_token() -> str:
def get_auth_tokens() -> Dict[str, str]:
token = os.environ.get("TRAVIS_TOKEN")
if not token:
try:
Expand All @@ -37,7 +41,7 @@ def get_auth_token() -> str:
" information."
)
token = r.stdout.strip()
return token
return {"travis": token, "github": get_github_token()}

@cached_property
def client(self) -> APIClient:
Expand All @@ -49,6 +53,10 @@ def client(self) -> APIClient:
},
)

@cached_property
def ghrepo(self) -> Repository:
return Github(self.gh_token).get_repo(self.repo)

def paginate(
self, path: str, params: Optional[Dict[str, str]] = None
) -> Iterator[dict]:
Expand All @@ -69,7 +77,11 @@ def get_build_assets(
f"/repo/{quote(self.repo, safe='')}/builds",
params={"include": "build.jobs"},
):
run_event = EventType.from_travis_event(build["event_type"])
event_type = EventType.from_travis_event(build["event_type"])
if event_type is None:
raise ValueError(
f"Build has unknown event type {build['event_type']!r}"
)
if build["started_at"] is None:
### TODO: If there are any builds with a higher number that
### have already started and finished, this can lead to the
Expand All @@ -86,12 +98,32 @@ def get_build_assets(
else:
log.info("Found build %s", build["number"])
self.register_build(ts, True)
if run_event in event_types:
if event_type in event_types:
commit = self.get_commit(build, event_type)
for job in build["jobs"]:
yield TravisJobLog.from_job(self.client, build, job)
yield TravisJobLog.from_job(
self.client, build, job, commit, event_type
)
else:
log.info("Event type is %r; skipping", build["event_type"])

def get_commit(self, build: Dict[str, Any], event_type: EventType) -> Optional[str]:
if event_type in (EventType.CRON, EventType.PUSH):
commit = build["commit"]["sha"]
assert isinstance(commit, str)
return commit
elif event_type is EventType.PULL_REQUEST:
pr = self.ghrepo.get_pull(build["pull_request_number"])
if pr.merge_commit_sha == build["commit"]["sha"]:
return pr.head.sha
else:
log.info(
"Could not determine PR head commit for build; setting to 'UNK'"
)
return None
else:
raise AssertionError(f"Unhandled EventType: {event_type!r}")


class TravisJobLog(BuildLog):
job: str
Expand All @@ -103,28 +135,23 @@ def from_job(
client: APIClient,
build: Dict[str, Any],
job: Dict[str, Any],
commit: Optional[str],
event_type: EventType,
) -> "TravisJobLog":
created_at = isoparse(build["started_at"])
event = EventType.from_travis_event(build["event_type"])
if event is None:
raise ValueError(f"Build has unknown event type {build['event_type']!r}")
event_id: str
commit: Optional[str]
if event is EventType.CRON:
if event_type is EventType.CRON:
event_id = created_at.strftime("%Y%m%dT%H%M%S")
commit = build["commit"]["sha"]
elif event is EventType.PUSH:
elif event_type is EventType.PUSH:
event_id = build["branch"]["name"]
commit = build["commit"]["sha"]
elif event is EventType.PULL_REQUEST:
elif event_type is EventType.PULL_REQUEST:
event_id = str(build["pull_request_number"])
commit = None
else:
raise AssertionError(f"Unhandled EventType: {event!r}")
raise AssertionError(f"Unhandled EventType: {event_type!r}")
return cls(
client=client,
created_at=created_at,
event_type=event,
event_type=event_type,
event_id=event_id,
build_commit=build["commit"]["sha"],
commit=commit,
Expand Down
19 changes: 19 additions & 0 deletions src/tinuous/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from collections import deque
from datetime import datetime, timezone
import logging
import os
from pathlib import Path
import subprocess
from typing import Dict, Iterator, cast

import requests
Expand Down Expand Up @@ -54,3 +56,20 @@ def expand_template(

def fstring(s: str, **kwargs: str) -> str:
return cast(str, eval(f"f{s!r}", {}, kwargs))


def get_github_token() -> str:
token = os.environ.get("GITHUB_TOKEN")
if not token:
r = subprocess.run(
["git", "config", "hub.oauthtoken"],
stdout=subprocess.PIPE,
universal_newlines=True,
)
if r.returncode != 0 or not r.stdout.strip():
raise RuntimeError(
"GitHub OAuth token not set. Set via GITHUB_TOKEN"
" environment variable or hub.oauthtoken Git config option."
)
token = r.stdout.strip()
return token