-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
64 lines (57 loc) · 2.27 KB
/
action.yml
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
name: 'checkout github repo'
description: 'Clone github repo and checkout commit'
branding:
icon: 'archive'
color: 'green'
inputs:
submodules:
description: 'init submodules, can be true or false'
required: false
default: true
runs:
using: "composite"
steps:
- name: clean
run: |
echo "clean"
# NOTE: ls on macosx does not support long names of keys, e.g. --almost-all
for f in $(ls -A); do
rm -rf $f
done
shell: bash
- name: clone repo
run: |
# On github public runners the current directory is owned by some other user.
# To avoid git unsafe repository error, add current directory as a safe one to git config.
git config --global --add safe.directory $(pwd)
# set credentials using "GIT_ASKPASS" to avoid the token to present in output of "git remote -v"
echo "#!/bin/bash\necho ${{ github.token }}" > ~/git_askpass.sh
chmod +x ~/git_askpass.sh
echo "clone"
GIT_ASKPASS=~/git_askpass.sh git clone --quiet https://github.com/${{ github.repository }} .
ref_type=$(echo ${{ github.ref }} | sed -E -n -e 's/^refs\/([^/]*)\/.*$/\1/p')
ref=$(echo ${{ github.ref }} | sed -E -n -e 's/^refs\/[^/]*\/(.*)$/\1/p')
echo "ref = $ref"
echo "ref_type = $ref_type"
case $ref_type in
pull)
echo "ref is a pull request, fetch it"
git fetch origin +refs/pull/$ref:refs/remotes/origin/pull/$ref
ref="origin/pull/$ref"
;;
*)
echo "use commit sha as ref"
ref=${{ github.sha }}
;;
esac
echo "checkout $ref"
git checkout $ref
if [ "${{ inputs.submodules }}" == "true" ] && [ -f ".gitmodules" ]; then
echo "clone submodules"
# replace ssh to https in .gitmodules
# NOTE: $ in front of sed's expression string is needed to make macosx treat \t as tab characters, then also \1 needs to be \\1
sed -E -i -e $'s/^[ \t]*url[ \t]*=[ \t]*git@github.com:([^\/]*\/[^\/]*)[ \t]*$/\turl = https:\/\/${{ github.token }}@github.com\/\\1/g' .gitmodules
git submodule init
git submodule update --recursive --remote
fi
shell: bash