-
Notifications
You must be signed in to change notification settings - Fork 7
/
buddy.inc.sh
125 lines (116 loc) · 3.3 KB
/
buddy.inc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
# shellcheck disable=SC2034
set -euo pipefail
function yp_ci_env_buddy() {
[[ "${BUDDY:-}" = "true" ]] || return 0
export CI=true
YP_CI_NAME=Buddy
YP_CI_PLATFORM=buddy
YP_CI_SERVER_HOST=buddy.works
YP_CI_REPO_SLUG=${BUDDY_REPO_SLUG:-}
YP_CI_ROOT=${WORKING_DIR:-}
YP_CI_IS_CRON=
[[ "${BUDDY_PIPELINE_TRIGGER_MODE:-}" != "SCHEDULE" ]] || YP_CI_IS_CRON=true
YP_CI_IS_PR=
[[ -z "${BUDDY_EXECUTION_PULL_REQUEST_ID:-}" ]] || YP_CI_IS_PR=true
# 1 pipeline -> n jobs
YP_CI_JOB_ID=${BUDDY_EXECUTION_ID:-}
YP_CI_PIPELINE_ID=${BUDDY_PIPELINE_ID:-}
YP_CI_JOB_URL=${BUDDY_EXECUTION_URL:-}
YP_CI_PIPELINE_URL=${BUDDY_PIPELINE_URL:-}
YP_CI_PR_NUMBER=
YP_CI_PR_URL=
YP_CI_PR_REPO_SLUG=
YP_CI_PR_GIT_HASH=
YP_CI_PR_GIT_BRANCH=
[[ "${YP_CI_IS_PR}" != "true" ]] || {
YP_CI_PR_NUMBER=${BUDDY_EXECUTION_PULL_REQUEST_NO:-}
YP_CI_PR_URL=https://github.com/${YP_CI_REPO_SLUG}/pull/${YP_CI_PR_NUMBER}
YP_CI_PR_REPO_SLUG= # TODO
YP_CI_PR_GIT_HASH= # TODO
YP_CI_PR_GIT_BRANCH=${BUDDY_EXECUTION_PULL_REQUEST_HEAD_BRANCH:-}
}
YP_CI_GIT_HASH=${BUDDY_EXECUTION_REVISION:-}
YP_CI_GIT_BRANCH=${BUDDY_EXECUTION_BRANCH:-}
[[ "${YP_CI_IS_PR}" != "true" ]] || YP_CI_GIT_BRANCH=${BUDDY_EXECUTION_PULL_REQUEST_BASE_BRANCH:-}
YP_CI_GIT_TAG=${BUDDY_EXECUTION_TAG:-}
YP_CI_DEBUG_MODE=${YP_CI_DEBUG_MODE:-}
}
function yp_ci_printvars_buddy() {
printenv_all | sort -u | grep \
-e "^CI=" \
-e "^BUDDY[=_]" \
-e "^WORKING_DIR="
}
function yp_ci_known_env_buddy() {
# see https://buddy.works/docs/pipelines/environment-variables#default-environment-variables
cat <<EOF
CI
BUDDY
BUDDY_EXECUTION_BRANCH
BUDDY_EXECUTION_CHANGELOG
BUDDY_EXECUTION_CHANGELOG_ADDED
BUDDY_EXECUTION_CHANGELOG_CHANGED
BUDDY_EXECUTION_CHANGELOG_DELETED
BUDDY_EXECUTION_CLEAR_CACHE
BUDDY_EXECUTION_COMMENT
BUDDY_EXECUTION_ID
BUDDY_EXECUTION_MODE
BUDDY_EXECUTION_PREVIOUS_REVISION
BUDDY_EXECUTION_PREVIOUS_REVISION_MESSAGE
BUDDY_EXECUTION_PREVIOUS_REVISION_SUBJECT
BUDDY_EXECUTION_PULL_REQUEST_BASE_BRANCH
BUDDY_EXECUTION_PULL_REQUEST_HEAD_BRANCH
BUDDY_EXECUTION_PULL_REQUEST_ID
BUDDY_EXECUTION_PULL_REQUEST_NO
BUDDY_EXECUTION_REFRESH
BUDDY_EXECUTION_REVISION
BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL
BUDDY_EXECUTION_REVISION_COMMITTER_NAME
BUDDY_EXECUTION_REVISION_MESSAGE
BUDDY_EXECUTION_REVISION_SHORT
BUDDY_EXECUTION_REVISION_SUBJECT
BUDDY_EXECUTION_REVISION_URL
BUDDY_EXECUTION_START_DATE
BUDDY_EXECUTION_TAG
BUDDY_EXECUTION_TIME
BUDDY_EXECUTION_URL
BUDDY_EXECUTION_WARNINGS_COUNT
BUDDY_FAILED_ACTION_LOGS
BUDDY_FAILED_ACTION_NAME
BUDDY_INVOKER_AVATAR_URL
BUDDY_INVOKER_EMAIL
BUDDY_INVOKER_ID
BUDDY_INVOKER_NAME
BUDDY_INVOKER_URL
BUDDY_PIPELINE_ID
BUDDY_PIPELINE_NAME
BUDDY_PIPELINE_REF_NAME
BUDDY_PIPELINE_TARGET_SITE_URL
BUDDY_PIPELINE_TRIGGER_MODE
BUDDY_PIPELINE_URL
BUDDY_PROJECT_NAME
BUDDY_PROJECT_NAME_ID
BUDDY_PROJECT_URL
BUDDY_REPO_SLUG
BUDDY_REPO_SSH_URL
BUDDY_SCM_PROVIDER
BUDDY_SCM_URL
BUDDY_WORKSPACE_DOMAIN
BUDDY_WORKSPACE_ID
BUDDY_WORKSPACE_NAME
BUDDY_WORKSPACE_URL
EOF
# undocumented but observed
cat <<EOF
BUDDY_EXECUTION_EVENT_TYPE
BUDDY_EXECUTION_HASH
BUDDY_EXECUTION_PARALLEL_SLOT_NO
BUDDY_EXECUTION_REF
BUDDY_EXECUTION_REFS
BUDDY_EXECUTION_WEBHOOK_PAYLOAD
BUDDY_PIPELINE_REFS
BUDDY_SLOT_NO
WORKING_DIR
EOF
}