Skip to content

Commit c87f91f

Browse files
committed
Report commit status to GitHub
1 parent e92be01 commit c87f91f

File tree

3 files changed

+71
-36
lines changed

3 files changed

+71
-36
lines changed

.travis.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# The scala/scala travis job triggers a build of scala/scala-dist with `mode=release`. For
2+
# the other modes (see below), use the web UI to trigger a build.
3+
#
4+
# Additional env vars are defined using a `before_install` custom config(*), for example
5+
# before_install: export version=2.12.N scala_sha=abc123 mode=release
6+
#
7+
# Available modes:
8+
# - `release` to build native packages and upload them to S3
9+
# - `archive` to copy archives to chara (for scala-lang.org)
10+
# - `update-api` to update the scaladoc api symlinks
11+
#
12+
# (*) Using an `env: global: ...` section does not work because that overrides the default `env`
13+
# from .travis.yml. For releases triggered with the REST API we could use the "merge mode", but
14+
# not when triggering from the web UI. Anyway, `before_install` works well.
15+
116
# we need rpmbuild but it's unlikely to be whitelisted, according to
217
# https://github.com/travis-ci/apt-package-whitelist/pull/1700
318
sudo: required
@@ -13,18 +28,33 @@ env:
1328
global:
1429
# PRIV_KEY_SECRET
1530
- secure: "NlnFqZs4mvCi63GqCdUNDsx9BoiyrjgoV0cUaKlhVYp49/qAMlEaKf6JABWy/oCHoWsTyysyLEtZLsWfjAyE4+FUHSzngNUHVFBbtyudA6aKQ7jMsqkcMM/K0h+ymnhHSv8bugc8jXKFgmfYk4YTi5dZgv8CAOSQFAFUaxVdYTY="
16-
# APPVEYOR_TOKEN
31+
# APPVEYOR_TOKEN (login with GitHub as lrytz, use the scala organization)
1732
- secure: "aHM0UWkbFN0bXQja2f9lUcSgqHzXYkYqqV8/nP5MTLKJG8BpuaLYxI4gHfkPmxSm9/TTniA3zUVN//lJTvhco5J5Dtxfo5DeCLWsjQcQxrsgAFD97FpMpGbtFAViZuiv7SdPGvzXQY6AwvteBpxOday4T224aH5OjZJ0DxySx8Q="
18-
# TRAVIS_TOKEN
33+
# TRAVIS_TOKEN (login with GitHub as lrytz)
1934
- secure: "K6G3SeMRMgC8JUZADyd4RKvQpgHOZb8/8kk3AlDtRWZmrBPkZpTrtcuQLYXRiEAO/beQH956i3+uDeFryF079YTJZKtdqLTxwXS53gVurOv9VVbZFubu4HzXWMWeCIi9Np7S0eB1qc4NIKB+T5pbmIfEFGKThBGK179uwf2lqQ8="
2035
# AWS_ACCESS_KEY_ID
2136
- secure: "BrsLFLXLdJ3aesJGuoVXFdKluYl7QYBYjn5+ttoep2nc6/E+L3UDaR//ztxwex4a9yFi5q2jCs911FzVsk78ODamr5w8FBlOuu06RoVx642+U/agG7yUdAtvEzH2KVTBNjY0oYHZ+OlVEkeYgnkrsbfki+ujPWEnxkakWyrGtJw="
2237
# AWS_SECRET_ACCESS_KEY
2338
- secure: "dv0pR9uqnLyKVHu1L1nvl5TVpo3bOxh4icLNybwFyCFQd9XiM/RU8Vhx3svZqqnAG+GiCDSiCaBQkTLUS5u9e+9eVw3cUj5meNr9EW673f8D6H8Tr433jlvu54CynD9DsBjhNo/xIrECOKTq+0wu480OLSjOkuNoclG2dSm4Dis="
39+
# GITHUB_OAUTH_TOKEN (for GitHub user scala-jenkins, same token as scabot)
40+
- secure: "FtrGQs3tHwOPZOXi1xDcCo1KtP1rUfaiK+l5lrjzXhuCjtWkG+MHB0VI1D1QwbXh+BiRdYIyfUyKBa1I+lRrjKx5aDgxZ7EweML5CtzIu7hAuxbc6zchC3R0qZJe20DcM1BjokCXi2EnKtgABIBuCP0KY4WiH0NQkGjZsemoCAQ="
2441

2542
script:
43+
- source scripts/common
44+
- if [[ "$scala_sha" != "" ]]; then postCommitStatus "pending"; fi
2645
- admin/build.sh
2746

47+
after_script:
48+
- |
49+
if [[ "$scala_sha" != "" ]]; then
50+
if [[ "$TRAVIS_TEST_RESULT" == "0" ]]; then
51+
local state="success"
52+
else
53+
local state="failure"
54+
fi
55+
postCommitStatus $state
56+
fi
57+
2858
cache:
2959
directories:
3060
- $HOME/.ivy2

admin/build.sh

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,6 @@
22

33
set -ex
44

5-
# Triggering jobs for a release:
6-
# - Open https://travis-ci.org/scala/scala-dist
7-
# - On the right: "More options" - "Trigger build"
8-
# - Chose the branch and enter a title for the build in the commit message filed
9-
# - Add a `before_install` custom config (see below) to set the `mode` and `version` env vars.
10-
# Using an `env: global: ...` section does not work because that overrides the default `env`
11-
# from .travis.yml. There's no way to specify the "merge mode" (*) from the web UI, that only
12-
# works in the REST API. We use `before_install` and assume it's not used otherwise.
13-
# (*) https://docs.travis-ci.com/user/triggering-builds/#Customizing-the-build-configuration
14-
# - Available modes:
15-
# - `release` to build native packages and upload them to S3
16-
# - `archive` to copy archives to chara (for scala-lang.org)
17-
# - `update-api` to update the scaladoc api symlinks
18-
# In all of the above modes, the `version` needs to be specified.
19-
#
20-
# before_install: export version=2.12.N mode=release
21-
22-
235
# Encryping files (if you need to encrypt a new file but no longer have the secret, create a new
246
# secret and re-encrypt all files):
257
#
@@ -32,7 +14,6 @@ set -ex
3214
# 4. Decrypt the file
3315
# openssl aes-256-cbc -d -pass "pass:$PRIV_KEY_SECRET" -in admin/files/jenkins_lightbend_chara.enc > ~/.ssh/jenkins_lightbend_chara 2>/dev/null
3416

35-
3617
function ensureVersion() {
3718
local verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
3819
[[ "$version" =~ $verPat ]] || {
@@ -54,44 +35,39 @@ function setupSSH() {
5435
chmod 700 ~/.ssh && $(cd ~/.ssh && chmod 600 config known_hosts jenkins_lightbend_chara)
5536
}
5637

57-
curlOut="curlOut.txt"
58-
59-
function checkStatus() {
60-
cat $curlOut
61-
rm -f $curlOut
62-
[[ "$1" == "$2" ]] || {
63-
echo "Failed to start smoketest job"
64-
exit 1
65-
}
66-
}
67-
6838
function triggerMsiRelease() {
6939
local jsonTemplate='{ "accountName": "scala", "projectSlug": "scala-dist", "branch": "%s", "commitId": "%s", "environmentVariables": { "mode": "%s", "version": "%s" } }'
7040
local json=$(printf "$jsonTemplate" "$TRAVIS_BRANCH" "$TRAVIS_COMMIT" "$mode" "$version")
7141

7242
local curlStatus=$(curl \
73-
-s -o $curlOut -w "%{http_code}" \
43+
-s -o /dev/null -w "%{http_code}" \
7444
-H "Authorization: Bearer $APPVEYOR_TOKEN" \
7545
-H "Content-Type: application/json" \
7646
-d "$json" \
7747
https://ci.appveyor.com/api/builds)
7848

79-
checkStatus $curlStatus "200"
49+
[[ "$curlStatus" == "200" ]] || {
50+
echo "Failed to start AppVeyor build"
51+
exit 1
52+
}
8053
}
8154

8255
function triggerSmoketest() {
8356
local jsonTemplate='{ "request": { "branch": "%s", "message": "Smoketest %s", "config": { "before_install": "export version=%s" } } }'
8457
local json=$(printf "$jsonTemplate" "$TRAVIS_BRANCH" "$version" "$version")
8558

8659
local curlStatus=$(curl \
87-
-s -o $curlOut -w "%{http_code}" \
60+
-s -o /dev/null -w "%{http_code}" \
8861
-H "Travis-API-Version: 3" \
8962
-H "Authorization: token $TRAVIS_TOKEN" \
9063
-H "Content-Type: application/json" \
9164
-d "$json" \
9265
https://api.travis-ci.org/repo/scala%2Fscala-dist-smoketest/requests)
9366

94-
checkStatus $curlStatus "202"
67+
[[ "$curlStatus" == "202" ]] || {
68+
echo "Failed to start travis build"
69+
exit 1
70+
}
9571
}
9672

9773
if [[ "$TRAVIS_EVENT_TYPE" == "api" ]]; then

scripts/common

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://github.com/travis-ci/docs-travis-ci-com/issues/949
2+
function travis_fold_start() {
3+
echo ""
4+
echo -e "travis_fold:start:$1\033[33;1m$2\033[0m"
5+
}
6+
7+
function travis_fold_end() {
8+
echo -e "\ntravis_fold:end:$1\r"
9+
echo ""
10+
}
11+
12+
# Params:
13+
# - state: pending / success / failed / error
14+
function postCommitStatus() {
15+
local jsonTemplate='{ "state": "%s", "target_url": "%s", "description": "%s", "context": "%s"}'
16+
local json=$(printf "$jsonTemplate" "$1" "https://travis-ci.org/scala/scala-dist/builds/$TRAVIS_BUILD_ID" "$1" "travis/scala-dist/$version/$mode")
17+
18+
local curlStatus=$(curl \
19+
-s -o /dev/null -w "%{http_code}" \
20+
-H "Accept: application/vnd.github.v3+json" \
21+
-H "Authorization: token $GITHUB_OAUTH_TOKEN" \
22+
-d "$json" \
23+
https://api.github.com/repos/scala/scala/statuses/$scala_sha)
24+
25+
[[ "$curlStatus" == "201" ]] || {
26+
echo "Failed to publish GitHub commit status"
27+
exit 1
28+
}
29+
}

0 commit comments

Comments
 (0)