Skip to content

Commit 78fb79d

Browse files
committed
Log directly to GitHub
1 parent ad1420d commit 78fb79d

File tree

1 file changed

+53
-88
lines changed

1 file changed

+53
-88
lines changed

invfile.lua.md

Lines changed: 53 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ We also determine where the results will be stored:
7070

7171
quay_prefix = 'mulled'
7272
namespace = 'quay.io/' .. quay_prefix
73-
github_repo = 'mulled/api'
73+
github_repo = 'mulled/mulled'
7474

7575
current_build_id =
7676
'https://travis-ci.org/mulled/mulled/builds/'
@@ -519,41 +519,23 @@ contains one line, and the combination of `--raw-input` and `--slurp` makes
519519
`jq` convert this to a big string, with newlines as separators. This array is
520520
split and indexed with positional indexes.
521521

522-
Similar to the Quay.io repository description, the description and homepage are
523-
taken from the latest revision.
524-
525-
However, we have to make sure that the file containing 'old' revisions exists in
526-
the package information directory. If any old revisions exist, they are copied over,
527-
otherwise a new array is used.
528-
529-
.using(busybox)
530-
.withHostConfig({binds = {
531-
builddir .. ':/pkg',
532-
'./data:/data'
533-
}})
534-
.run('/bin/sh', '-c',
535-
'(tail -n +3 /data/api/_images/' .. package .. '.json'
536-
.. '|| echo "{}") > /pkg/info/github.json')
537-
538522
.using(jq)
539523
.withHostConfig({binds = {
540524
builddir .. ':/pkg',
541525
"./data:/data"
542526
}})
543-
.run('/jq-linux64 --raw-output --raw-input --slurp \'.|split("\n") as $i'
544-
.. '| ("---\n---\n" + ({'
545-
.. 'image: "' .. package .. '",'
527+
.run('/jq-linux64 -c --raw-input --slurp \'.|split("\n") as $i'
528+
.. '| {image: "' .. package .. '", '
546529
.. 'packager: "' .. packager .. '", '
547530
.. 'homepage: $i[0], description: $i[1], '
548-
.. 'versions: ($i[3] | fromjson | (.versions // []) | '
549-
.. ' map(select(.revision != "' .. new_revision
550-
.. '" )) + [{version: $i[2], revision: "' .. new_revision
551-
.. '", size: $i[4], date: (now | todate)}]),'
552-
.. 'buildurl: "' .. current_build_id .. '"}'
553-
.. '|tostring))\''
531+
.. 'travisid: ' .. ENV.TRAVIS_BUILD_ID .. ','
532+
.. 'travisslug: "' .. ENV.TRAVIS_REPO_SLUG .. '",'
533+
.. 'date: "\'$(date -Iseconds)\'", '
534+
.. 'version: $i[2], revision: "'
535+
.. new_revision .. '", size: $i[3]}\''
554536
.. ' /pkg/info/homepage /pkg/info/description '
555-
.. '/pkg/info/version /pkg/info/github.json /pkg/info/size '
556-
.. ' > /data/api/_images/' .. package .. '.json')
537+
.. '/pkg/info/version /pkg/info/size '
538+
.. ' >> /data/loglines.jsonl')
557539
end
558540

559541
# The Build Tasks
@@ -613,7 +595,7 @@ attach all predefined, package specific tasks to the overall tasks:
613595
end
614596
end
615597
deploy
616-
.runTask('main:commit_api_database')
598+
.runTask('main:upload_build_log')
617599
end
618600

619601
# Determining What To Build
@@ -622,55 +604,21 @@ It is highly inefficient to build every single package every time a build is
622604
invoked. In this tool, we restrict ourselves to building packages in versions
623605
that are not already registered in our API database.
624606

625-
Firstly, we fetch the current API 'database' from GitHub. This database is
626-
comprised of several JSON files containing common and revision specific
627-
information for each package. Each file may look like the following example
628-
(note the YAML frontmatter for Jekyll):
629-
630-
```json
631-
---
632-
---
633-
{
634-
"image": "bc",
635-
"packager": "alpine",
636-
"homepage": "http://www.gnu.org/software/bc/bc.html",
637-
"description": "An arbitrary precision numeric processing language (calculator)",
638-
"versions": [
639-
{
640-
"revision": "1",
641-
"version": "1.06.95-r2",
642-
"size": 5000,
643-
"date": "2016-01-26T11:00:02Z",
644-
"buildurl": "https://travis.ci-org./mulled/mulled/builds/203830"
645-
},
646-
{
647-
"revision": "2",
648-
"version": "1.06.95-r3",
649-
"size": 4000,
650-
"date": "2016-01-26T11:02:02Z",
651-
"buildurl": "https://travis.ci-org./mulled/mulled/builds/203831"
652-
}
653-
]
654-
}
655-
```
656-
657-
We clone the repository into a subdirectory called `data/api`:
658-
659607
inv.task('main:versions:clone_from_github')
660608
.using(git)
661-
.run('clone', 'https://github.com/mulled/api.git', 'data/api')
662-
663-
These data files still contain the YAML frontmatter, and have to be transformed
664-
to make easy use of them in later steps. A `jq` program is used to read them in,
665-
and store a single JSON object assinging a list of versions to each package.
666-
667-
local parseGithubImages = 'map({(.image): (.versions | map(.revision))}) | add // {}'
609+
.run('fetch', '--unshallow')
610+
.run('config', 'remote.origin.fetch',
611+
'+refs/heads/*:refs/remotes/origin/*')
612+
.run('fetch', 'origin', 'gh-pages')
613+
.run('checkout', 'origin/gh-pages',
614+
'--', '_builds')
668615

669616
inv.task('main:versions:process_versions_from_github')
670-
.using(busybox)
671-
.run('/bin/sh', '-c', 'tail -q -n +3 data/api/_images/*json > data/github_jsons.jsonl || touch data/github_jsons.jsonl')
672617
.using(jq)
673-
.run('/jq-linux64 --slurp \'' .. parseGithubImages .. '\' data/github_jsons.jsonl > data/github_versions')
618+
.run('cat _builds/* | grep -v -- "---" | /jq-linux64 --slurp --raw-output '
619+
.. '\'map(.packages)|flatten|group_by(.image)|'
620+
.. 'map({key: .[0].image, value: map(.revision)})|from_entries\' '
621+
.. ' > data/github_versions')
674622

675623
As the next step, we parse the list of locally defined packages and intersect
676624
this with the list of remotely available images. The `packages.tsv` is split
@@ -735,22 +683,39 @@ duplicates and tells the user.
735683

736684
# Final Steps
737685

738-
If we are doing a production build on Travis, we have to commit/push the new
739-
API database.
686+
If we are doing a production build on Travis, we have to upload the build log
687+
to GitHub.
740688

741-
inv.task('main:commit_api_database')
742-
.using(git)
743-
.withHostConfig({
744-
binds = {
745-
"./data/git/.gitconfig:/root/.gitconfig",
746-
"./data/netrc:/root/.netrc",
747-
"./data/api:/source"
748-
}})
749-
.run('add', '_images')
750-
.withConfig({entrypoint = {'/bin/sh', '-c'}})
751-
.run('git commit -m "Build '
752-
.. ENV.TRAVIS_BUILD_NUMBER .. '" || true')
753-
.run('git push origin gh-pages')
689+
inv.task('main:upload_build_log')
690+
.using(busybox)
691+
.run('touch', 'data/loglines.jsonl')
692+
.using(jq)
693+
.run('/jq-linux64 --slurp '
694+
.. '\'{title: "' .. ENV.TRAVIS_BUILD_NUMBER .. '",'
695+
.. 'packages: .}\' '
696+
.. 'data/loglines.jsonl > data/log.json')
697+
.using(busybox)
698+
.withHostConfig({binds = {
699+
'./data:/data'
700+
}})
701+
.run('/bin/sh', '-c', 'cat /data/log.json')
702+
.run('/bin/sh', '-c',
703+
'(echo "---"; '
704+
.. 'cat /data/log.json; '
705+
.. 'echo "---") > /data/build_log')
706+
.using(curl)
707+
.withConfig({
708+
env = {"TOKEN=" .. ENV.GITHUB_TOKEN}
709+
})
710+
.run('/bin/sh', '-c',
711+
'curl -X PUT '
712+
.. 'https://api.github.com/repos/'
713+
.. github_repo .. '/contents/_builds/'
714+
.. ENV.TRAVIS_BUILD_NUMBER .. '-$(date +%s).json '
715+
.. '-d \'{"message":"no ' .. ENV.TRAVIS_BUILD_NUMBER
716+
.. '", "branch": "gh-pages", "content": "'
717+
.. '\'$(base64 data/build_log | tr -d "\n")\'"}\' '
718+
.. '-HAuthorization:Bearer\\ $TOKEN ')
754719

755720
# Appendix
756721

0 commit comments

Comments
 (0)