-
Notifications
You must be signed in to change notification settings - Fork 7
/
github-fix
executable file
·62 lines (55 loc) · 2.44 KB
/
github-fix
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
#!/usr/bin/env bash
set -euo pipefail
# intended to be called as first thing in a github workflow, before bin/github-checkout
UID_COLON_GID="$(id -u -n):$(id -g -n)"
# GITHUB_WORKSPACE might not exist
[[ -d "${GITHUB_WORKSPACE}" ]] || {
echo "Creating GITHUB_WORKSPACE=${GITHUB_WORKSPACE}."
sudo mkdir -p ${GITHUB_WORKSPACE}
ls -lad ${GITHUB_WORKSPACE}
}
# GITHUB_WORKSPACE owned by 1001:116, makes it impossible to write in the folder
# NOTE try GNU format, then BSD, then fail
GITHUB_WORKSPACE_UID_COLON_GID=$(stat -c "%u:%g" ${GITHUB_WORKSPACE}) || \
GITHUB_WORKSPACE_UID_COLON_GID=$(stat -f "%Su:%Sg" ${GITHUB_WORKSPACE})
ls -lad ${GITHUB_WORKSPACE}
[[ "${GITHUB_WORKSPACE_UID_COLON_GID}" = "${UID_COLON_GID}" ]] || {
echo "Changing ownership of GITHUB_WORKSPACE=${GITHUB_WORKSPACE}"
echo "owned by ${GITHUB_WORKSPACE_UID_COLON_GID} to ${UID_COLON_GID}."
sudo chown ${UID_COLON_GID} ${GITHUB_WORKSPACE}
ls -lad ${GITHUB_WORKSPACE}
}
# GITHUB_ENV file isn't created,
# and thus it is possible that 'echo FOO=BAR >> ${GITHUB_ENV}' fails with 'No such file or directory'
# see https://github.com/actions/runner/issues/1445
[[ -e "${GITHUB_ENV}" ]] || {
echo "Creating GITHUB_ENV=${GITHUB_ENV}."
touch ${GITHUB_ENV} || sudo touch ${GITHUB_ENV}
sudo chown ${UID_COLON_GID} ${GITHUB_ENV}
ls -la ${GITHUB_ENV}
}
# GITHUB_ENV owned by 1001:116, makes it impossible to write to it
# unless one uses sudo i.e. 'echo FOO=BAR | sudo tee -a ${GITHUB_ENV}'
# NOTE stil recommended to use 'sudo tee'
GITHUB_ENV_UID_COLON_GID=$(stat -c "%u:%g" ${GITHUB_ENV}) || \
GITHUB_ENV_UID_COLON_GID=$(stat -f "%Su:%Sg" ${GITHUB_ENV})
ls -la ${GITHUB_ENV}
[[ "${GITHUB_ENV_UID_COLON_GID}" = "${UID_COLON_GID}" ]] || {
echo "Changing ownership of GITHUB_ENV=${GITHUB_ENV}"
echo "owned by ${GITHUB_ENV_UID_COLON_GID} to ${UID_COLON_GID}."
sudo chown ${UID_COLON_GID} ${GITHUB_ENV}
ls -la ${GITHUB_ENV}
}
# HOME set to /github/home, turns off sourcing ~/.profile, ~/.bash_profile, ~/.bashrc etc
# see https://github.com/actions/runner/issues/863
# see https://github.com/actions/runner/issues/1525
# see https://github.com/actions/runner/issues/1146
HOME_REAL=$(eval echo "~$(id -u -n)")
[[ "${HOME}" = "${HOME_REAL}" ]] || {
echo "Changing HOME=${HOME}"
echo "to ${HOME_REAL} for ${UID_COLON_GID}."
ls -la "${HOME}"
ls -la "${HOME_REAL}"
echo "By adding to ${GITHUB_ENV}."
echo "HOME=${HOME_REAL}" | sudo tee -a ${GITHUB_ENV}
}