Skip to content

Version poller

Version poller #9876

name: Version poller
on:
schedule:
- cron: '15 0 * * *' # UTC
push:
paths:
- .github/workflows/version_poller.yml
branches:
- main
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
poll:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Poll for latest version
env:
SSH_PRIVATE: ${{ secrets.SSH_PRIVATE }}
SSH_PUBLIC: ${{ secrets.SSH_PUBLIC }}
API_TOKEN: ${{ secrets.API_TOKEN }}
shell: bash
run: |
set -exo pipefail
current_version="$(cat .latest_version || printf '')"
curl https://api.github.com/repos/sourcegraph/sourcegraph/tags -o /tmp/sourcegraph_tags.json
tag="$(jq -r '.[] |.name' /tmp/sourcegraph_tags.json | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)"
if [ -n "$tag" ] && [[ "$current_version" < "$tag" ]] ; then
git config user.email "jens.brimfors@gmail.com"
git config user.name "GitHub Actions on behalf of Jens Brimfors"
mkdir "$HOME/.ssh"
echo "$SSH_PRIVATE" > "$HOME/.ssh/id_ed25519"
chmod 0700 "$HOME/.ssh/id_ed25519"
echo "$SSH_PUBLIC" > "$HOME/.ssh/id_ed25519.pub"
chmod 0700 "$HOME/.ssh/id_ed25519.pub"
eval "$(ssh-agent -s)"
ssh-add
echo "New version found! $tag"
echo "$tag" > .latest_version
sed -i "s|jensim/sourcegraph-server-oss:.*|jensim/sourcegraph-server-oss:$tag|" README.md
git add .latest_version README.md
git commit -m "Update .latest_version to $tag"
git push origin
curl -vf \
-X POST \
-u "jensim:$API_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/jensim/sourcegraph-release-train/actions/workflows/release_train.yml/dispatches \
-d '{"ref":"main"}'
else
exit 0
fi