-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (109 loc) · 4.96 KB
/
Check_On_Commit.yml
File metadata and controls
155 lines (109 loc) · 4.96 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Push Check on Changed Scripts
run-name: Action on push by ${{ github.actor }}
on:
workflow_call:
inputs:
image_to_use:
required: true
type: string
action_branch:
required: false
type: string
jobs:
Check_on_Changed_Scripts:
name: Push Check to ${{ github.head_ref }} by ${{ github.actor }}
runs-on: ubuntu-latest
container:
image: ${{ inputs.image_to_use }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- run: echo "Checking in ${{ inputs.image_to_use }}"
- uses: actions/checkout@v3
with:
token: ${{secrets.GITHUB_TOKEN}}
ref: ${{ github.ref_name }}
fetch-depth: 0
- name: Setup Workflow
id: setup_workflow
run: |
echo "Checking in ${{ inputs.image_to_use }}"
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
echo "$current_wd"
conda env list
# Configure git
git config --global --add safe.directory $current_wd
repo_name=${{ github.repository }}
access_token=${{ secrets.GITHUB_TOKEN }}
# Acquire main branch's latest hash for reference
# This is to handle the error message when a new branch
# is created from a push
response=$(curl -s -H "Authorization: Bearer $access_token" \
"https://api.github.com/repos/$repo_name/branches/main")
commit_hash=$(echo "$response" | \
grep -oP '(?<="sha": ")[^"]+' | head -n 1)
echo "Latest commit hash of main branch: $commit_hash"
echo "main_commit_hash=$commit_hash" >> $GITHUB_ENV
# Getting current commit information
echo "Current Commit SHA: ${{ github.sha }}"
echo "Previous Commit SHA: ${{ github.event.before }}"
# The series of 0 is the indication of creation from push
if [ "${{ github.event.before }}" = \
"0000000000000000000000000000000000000000" ]; then
echo "Branch ${{ github.event_name }} is created by current push."
echo "create_on_push=Yes" >> $GITHUB_ENV
else
echo "Branch ${{ github.event_name }} is not created from the current push."
echo "create_on_push=No" >> $GITHUB_ENV
fi
- id: Lint_check
name: Use lintr to check code
run: |
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
echo "$current_wd"
git config --global --add safe.directory "$current_wd"
git clone https://github.com/fnlcr-bids-sdsi/gitflow-R.git
cd gitflow-R
git checkout "${{ inputs.action_branch }}"
cd -
if [ "${{ env.create_on_push }}" = "Yes" ]; then
bash $current_wd/gitflow-R/src/Lint_on_Commit.sh \
"$current_wd" \
"${{ env.main_commit_hash }}"
else
bash $current_wd/gitflow-R/src/Lint_on_Commit.sh \
"$current_wd" \
"${{ env.main_commit_hash }}"
fi
- id: Unit_Test
name: Unit test for changed scripts
run: |
export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
echo "$current_wd"
bash $current_wd/gitflow-R/src/Check_on_Commit.sh \
"$current_wd" \
"${{ github.event.before }}"
- name: Undo Push (Off)
if: ${{ failure() }}
run: |
echo "Undo Push is turned off."
# if [ "${{ env.create_on_push }}" = "Yes" ]; then
# echo " Current GitHub branch is created with this push, nowhere to revert."
# else
# export current_wd="/__w/${GITHUB_REPOSITORY#*/}/${GITHUB_REPOSITORY#*/}"
# echo "$current_wd"
# export MY_GIT_TOKEN=${{secrets.GITHUB_TOKEN}}
# export MY_GIT_USERNAME=${{ github.actor }}
# export MY_GIT_EMAIL=${{ github.event.pusher.email }}
# git config --global user.name "$MY_GIT_USERNAME"
# git config --global user.email "$MY_GIT_EMAIL"
# git config --global url."https://api:$MY_GIT_TOKEN@github.com/".insteadOf "https://github.com/"
# git config --global url."https://ssh:$MY_GIT_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
# git config --global url."https://git:$MY_GIT_TOKEN@github.com/".insteadOf "git@github.com:"
# git clone https://github.com/${GITHUB_REPOSITORY}.git
# cd ${GITHUB_REPOSITORY#*/}
# git checkout ${{ github.ref_name }}
# git reset --hard ${{ github.event.before }}
# git push -f origin ${{ github.ref_name }}
# fi