GitHub Actions: How to access to the log of current build via Terminal - github

I'm trying to get familiar with Github Actions. I have configured my workflow in a way, that every time I push my code to GitHub, the code will automatically be built and pushed to heroku.
How can I access the build log information in terminal without going to github.com?

With the latest cli/cli tool named gh (1.9.0+), you can simply do
(from your terminal, without going to github.com):
gh run view <jobId> --log
# or
gh run view <jobId> --log-failed
See "Work with GitHub Actions in your terminal with GitHub CLI"
With the new gh run list, you receive an overview of all types of workflow runs whether they were triggered via a push, pull request, webhook, or manual event.
To drill down into the details of a single run, you can use gh run view, optionally going into as much detail as the individual steps of a job.
For more mysterious failures, you can combine a tool like grep with gh run view --log to search across a run’s entire log output.
If --log is too much information, gh run --log-failed will output only the log lines for individual steps that failed.
This is great for getting right to the logs for a failed step instead of having to run grep yourself.
And with GitHub CLI 2.4.0 (Dec. 2021), gh run list comes with a --json flag for JSON export.

Use
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/<github-user>/<repository>/actions/workflows/<workflow.yaml>/runs
https://docs.github.com/en/free-pro-team#latest/rest/reference/actions#list-workflow-runs
This will return a JSON with the following structure:
{
"total_count": 1,
"workflow_runs": [
{
"id": 30433642,
"node_id": "MDEyOldvcmtmbG93IFJ1bjI2OTI4OQ==",
"head_branch": "master",
"head_sha": "acb5820ced9479c074f688cc328bf03f341a511d",
"run_number": 562,
"event": "push",
"status": "queued",
"conclusion": null,
"workflow_id": 159038,
"url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642",
"html_url": "https://github.com/octo-org/octo-repo/actions/runs/30433642",
"pull_requests": [],
"created_at": "2020-01-22T19:33:08Z",
"updated_at": "2020-01-22T19:33:08Z",
"jobs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs",
"logs_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs",
"check_suite_url": "https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374",
"artifacts_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts",
"cancel_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel",
"rerun_url": "https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun",
"workflow_url": "https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038",
"head_commit": {...},
"repository": {...},
"head_repository": {...}
]
}
Access the jobs_url with a PAT that has repository admin rights.

Related

How can I add in-code annotations in PR reviews usign Github's `gh` tool?

On the Github web UI, I can click on a line and say something like:
Good architecture, but please pass the std::vector<std::uint8_t> hugedata as const &, to avoid a copy.
and bundle such comments as one review with a final verdict.
So far, I've only found gh pr review, which only allows me to generally approve/comment/reject a PR that I'm reviewing.
Is there a way to do detailed in-code reviews using the gh CLI?
if not, how can I use the github api to do that myself?
gh doesn't seem to have built in support for this, but you can still use gh api to call the API:
Note the repository owner, repository name, and pull request ID
Get a diff of the pull request so you can get the right files and positions
gh api \
-H "Accept: application/vnd.github.v3.diff" \
/repos/OWNER/REPO/pulls/ID
Note any files you want to comment on after +++
Note any positions you want to comment on after ## (by number of lines after that line)
Create a pull request review with your comments (using the file as path, the line offset from the start of the hunk as position, and your commend as body)
gh api \
-X POST \
/repos/OWNER/REPO/pulls/ID/reviews \
-d '{ "comments": [{"path": ...,"position": ...,"body": ...}, ...] }'
Submit the pull request review on GitHub (alternatively if you want to automate this, add the body and event properties to your review's body)

How can I get the user name of committer in each commit in a project in Git?

I am trying to make analysis between issues and commits of a project in git.
I am getting the name and email of the committer and author from git using the command below:
git log --pretty="%an %ae %cn %ce"
I am using 'curl -i "https://api.github.com/repos/<repo-owner>/<repo-name>/issues"' to download the issues. This returns the username[login name] for each issue not the name of the user as it is in the git log report:
{ "url": "https://api.github.com/repos/<repo-owner>/<repo-name>/issues/17625",
"node_id": "MDExOlB1bGxSZXF1ZXN0NTA5NDYyMjgz",
"number": 17625,
"title": "......",
"user": {
**"login": "xxxxxx",**
"id": 43045863,
....
"type": "User",
},
I check if the issue and commit has been made by the same user. Since I cannot get the username of committer, I cannot relate them. Is there a way to get the username of each commit on a project in git?

Read PR Title of a project on github

Is it possible to read the PR Title of a github repo?
I want to do some analysis over the data, currently I go and manually check the title and sometimes PR are very large in number
Any guidance will be helpful.
One way to do that is using the GitHub API. For example,
to get the pull request URLs and their titles in JSON format of someuser in somerepo, using curl and jq you could do:
curl -s https://api.github.com/repos/someuser/somerepo/pulls | jq '[.[] | { url: .url, title: .title }]'
The output will look something like:
[
{
"url": "https://api.github.com/repos/SonarSource/sonarlint-visualstudio/pulls/159",
"title": "Remove the locally copied Alm.Authentication classes and use the NuGe…"
},
{
"url": "https://api.github.com/repos/SonarSource/sonarlint-visualstudio/pulls/108",
"title": "New settings for Nuget package installation"
}
]

Rest API Testing from commandline

I am preparing a SDK, and SDK as of now, does not have CI system separately.
I want to test some REST endpoints which should be available when the user uses SDK to create the software and try to run with our framework.
I have written all the manual steps in shell script and planning to put the script as crontab to run it every few hours.
Now, for rest end point testing, I was thinking of just using curl and checking if we getting data back. but this can turn into a lot of work,as we expand the functionality. I looked into frisby framework which kind of suits my needs.
Is there any recommendation for allowing me to test rest services when the framework software is started.
Probably swat is exactly what you need. Reasons :
This is DSL for web, rest services test automation
it uses curl command line API to create http requests
it is both DSL and command line tool to run test scenarios written on DSL
it is configurable both from bash style scripts and general configs
it is very easy to start with
probably in your case curl based test cases could be easily converted into swat DSL format
(*) disclosure - I am the author of swat.
I have created a very small bash script to test JSON APIs which might be useful. It uses jq and curl as dependencies. curl for making request and jq for JSON processing.It is only designed to test JSON APIs.
Link: api-test
Every API call you want to run is stored in a JSON file with format below:
{
"name": "My API test",
"testCases": {
"test_case_1": {
"path": "/path_1",
"method": "POST",
"description": "Best POST api",
"body": {
"value": 1
},
"header": {
"X-per": "1"
}
},
}
"url": "http://myapi.com"
}
To run a test case:
api-test -f test.json run test_case_1
api-test -f test.json run all # run all API call at once.
It will produce output in an organized way
Running Case: test_case_1
Response:
200 OK
{
"name": "Ram",
"full_name": "Ram Shah"
}
META:
{
"ResponseTime": "0.078919s",
"Size": "235 Bytes"
}
It also supports automated testing of API with jq JSON comparison and normal equality/subset comparisons.

Track number of download of a release (binaries) on Github

So now you can manage and publish your binaries directly on Github, the feature is back from early this month (source).
I've been looking around Github interface and I haven't seen a download tracker. This is a feature Google Code offer and I was wondering if Github has the same.
Please note, I am not interested to know the number of download of a repo, this is a different topic.
Based on Petros answer, I used the two following curl command:
To get the list of all releases including their id and number of
download:
curl -i https://api.github.com/repos/:owner/:repo/releases -H "Accept: application/vnd.github.manifold-preview+json"
For example to list all the release for the OpenRefine project:
curl -i https://api.github.com/repos/openrefine/openrefine/releases -H "Accept: application/vnd.github.manifold-preview+json"
Then to get details on each release (you will need to run the first query to get the release id)
curl -i https://api.github.com/repos/:owner/:repo/releases/assets/:release_id -H "Accept: application/vnd.github.manifold-preview+json"
With the same example to list the details including download number for google-refine-2.5-r2407.zip
curl -i https://api.github.com/repos/openrefine/openrefine/releases/assets/6513 -H "Accept: application/vnd.github.manifold-preview+json"
You can use the GitHub API to get the download_count among other things for a single release asset:
http://developer.github.com/v3/repos/releases/#get-a-single-release-asset
This is how it looks currently, but please check the link above just in case anything changed since this answer was written.
GET /repos/:owner/:repo/releases/assets/:id
{
"url": "https://api.github.com/repos/octocat/Hello-World/releases/assets/1",
"id": 1,
"name": "example.zip",
"label": "short description",
"state": "uploaded",
"content_type": "application/zip",
"size": 1024,
"download_count": 42,
"created_at": "2013-02-27T19:35:32Z",
"updated_at": "2013-02-27T19:35:32Z"
}
You can add a badge to your github repo. See this answer for more details.
Also, there is a nifty project that shows all of this data in a nice website which is over here: https://www.somsubhra.com/github-release-stats/