Skip to content

add release workflows #128

add release workflows

add release workflows #128

Workflow file for this run

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 "[email protected]"
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@v4
with:
name: docs-${{matrix.python-version}}-${{ github.run_id }}
path: doc/build/html
overwrite: true # v4 requires unique names; this will delete existing before uploading
- 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 [email protected]: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 *