-
Notifications
You must be signed in to change notification settings - Fork 20
212 lines (186 loc) · 6.93 KB
/
main.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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: main
on: [push]
jobs:
test:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: git setup
# Set up git and export env vars to be used in later steps.
id: git-setup
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "WORKDIR=$(pwd)" >> $GITHUB_ENV
- name: build new conda env
run: |
eval "$(conda shell.bash hook)"
conda install -n base mamba -y --channel conda-forge
mamba create -p ./env -y python=${{ matrix.python-version }} --file test-requirements.txt --channel conda-forge --channel bioconda
conda activate ./env
pip install -e .
- name: run pytests
# pytests and doctests happen here
run: |
eval "$(conda shell.bash hook)"
conda activate ./env
pytest -vv --doctest-modules trackhub
- name: build docs
run: |
# To make sure that the links in the built docs refer to the correct
# branch on the trackhub-demo repo, we replace the branch names in the
# .rst files. Note if we're on master branch then this is a no-op.
eval "$(conda shell.bash hook)"
conda activate ./env
conda env export
(
cd doc
find . -name "*.rst" | xargs sed -i "s|trackhub-demo/master|trackhub-demo/$BRANCH|g"
make doctest html
)
- name: test command-line script
# Ensure that the installed command-line script can be run and creates
# the correct files
run: |
eval "$(conda shell.bash hook)"
conda activate ./env
trackhub_from_excel --template
trackhub_from_excel --create-example a.xlsx
trackhub_from_excel --excel-file a.xlsx
err=0
for f in template.xlsx a.xlsx staging staging/test_excel_to_trackhub.hub.txt; do
if [ ! -e $f ]; then
echo "file $f not present!"
err=1
fi
done
if [ err == 1 ]; then
exit 1
fi
- name: upload the just-built docs as an artifact
uses: actions/upload-artifact@v2
with:
name: docs
path: doc/build/html
- name: commit built docs to gh-pages
# The changes aren't actually pushed unless we're on the master branch
# (see next step).
#
# Note that cloning just the gh-pages branch to a new directory ended
# up being easier than staying in this directory and copying stuff
# around within it.
run: |
git clone \
--single-branch \
--branch gh-pages "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" \
/tmp/docs
# recall that this does leave hidden files
rm -rf /tmp/docs/*
cp -r doc/build/html/* /tmp/docs
touch /tmp/docs/.nojekyll
cd /tmp/docs
git add .
if git diff --cached --quiet; then
echo "no changes; nothing to commit"
else
git commit -m 'update docs'
fi
cd $WORKDIR
- name: push docs to gh-pages branch
# Push to gh-pages.
# (but only if we're on the master branch)
# This is how the docs get hosted on https://github.io/daler/trackhub.
if: ${{ github.ref == 'refs/heads/master' }}
run: |
cd /tmp/docs
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/daler/trackhub" gh-pages
cd $WORKDIR
- name: build example hubs
# Build example hubs into the "example_hubs" directory.
# See the ci/build_examples.py script for details. Also note that since
# we were last on the gh-pages branch from the last step, we need to
# explicitly check out the branch that this PR is for.
run: |
git branch
git checkout $BRANCH
eval "$(conda shell.bash hook)"
conda activate ./env
ci/build_examples.py
- name: start ssh agent
# Start the SSH agent so that subsequent steps don't need additional SSH
# setup.
# The private key has been added as a secret to the trackhub repo (the
# one running these tests), and the public key has been added as an
# allowed deploy key for the trackhub-demo repo (the one accepting
# pushes from this test). Note that this method ensures that the key is
# never saved to disk, and GitHub Actions automatically protects the
# secrets from being echoed.
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}"
- name: push built hubs to trackhub-demo repo
# Push to the trackhub-demo repo
# This creates a matching branch on the trackhub-demo repo, cleans out
# everything, and copies over the contents of the just-built
# "example_hubs" directory to that matching branch. This lets us
# inspect the hubs and correct them if needed on a branch before
# merging to master.
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
set -x
here=$(pwd)
git clone git@github.com:daler/trackhub-demo.git /tmp/trackhub-demo
cd /tmp/trackhub-demo
git checkout -B $BRANCH
git rm -rf ./*
# Note -L to follow links
cp -rLv $here/example_hubs/* /tmp/trackhub-demo
git add -f .
ls
git status
# It's possible that the $BRANCH here in the trackhub repo does not yet
# exist over in the trackhub-demo repo. In that case, we should be good
# to push immediately.
if [[ -z $(git ls-remote --heads origin $BRANCH) ]]; then
echo "remote branch $BRANCH does not exist"
git commit -m 'update hub'
git push origin $BRANCH --force
exit 0
fi
# Otherwise, only push to existing branch if there are changes.
if git diff origin/$BRANCH --quiet; then
echo "no changes to push to branch $BRANCH!";
else
echo "Diffs will be pushed to remote branch $BRANCH"
git commit -m 'update hub'
git push origin $BRANCH --force
fi
set +x
- name: hubChecks
# Check hubs
# Once hubs are uploaded to trackhub-demo repo, we need to check them
# to make sure they're accessible and have no glaring errors.
#
# See ci/check_hubs.py for details.
run: |
git checkout $BRANCH
eval "$(conda shell.bash hook)"
conda activate ./env
ci/check_hubs.py
- name: cleanup
# Remove all the ssh stuff we set up.
if: always()
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
ssh-add -D
rm -Rf *