Version poller #9879
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "[email protected]" | |
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 |