Detect IB Gateway Releases #430
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: Detect IB Gateway Releases | |
on: | |
schedule: | |
- cron: "0 6 * * *" | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: "bash -Eeuo pipefail -x {0}" | |
jobs: | |
detect-release: | |
runs-on: ubuntu-latest | |
outputs: | |
update: ${{ steps.check-update.outputs.has_update }} | |
channel: ${{ matrix.channel }} | |
strategy: | |
fail-fast: true | |
matrix: | |
channel: ["stable", "latest"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get Latest Version | |
id: version | |
run: | | |
res=$(curl -s https://download2.interactivebrokers.com/installers/tws/${{ matrix.channel }}-standalone/version.json | sed 's/tws${{ matrix.channel }}_callback(//g;s/);//g') | |
build_version=$(jq -r '.buildVersion' <<< "$res") | |
#build_dateTime=$(jq -r '.buildDateTime' <<< "$res") | |
echo "build_version=$build_version" >> $GITHUB_OUTPUT | |
#echo "build_dateTime=$build_dateTime" >> $GITHUB_OUTPUT | |
- name: Check if there is an update | |
id: check-update | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release list > /tmp/ibgateway-releases | |
if grep -qF '${{ steps.version.outputs.build_version }}' /tmp/ibgateway-releases | |
then | |
echo "has_update=false" >> $GITHUB_OUTPUT | |
else | |
echo "has_update=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Download | |
if: ${{ steps.check-update.outputs.has_update == 'true' }} | |
run: | | |
download_url='https://download2.interactivebrokers.com/installers/ibgateway/${{ matrix.channel }}-standalone/ibgateway-${{ matrix.channel }}-standalone-linux-x64.sh' | |
dest='ibgateway-${{ steps.version.outputs.build_version }}-standalone-linux-x64.sh' | |
curl -sSL "$download_url" --output "$dest" | |
sha256sum "$dest" > "${dest}.sha256" | |
- name: Create release | |
if: ${{ steps.check-update.outputs.has_update == 'true' }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create 'ibgateway-${{ matrix.channel }}@${{ steps.version.outputs.build_version }}' \ | |
-t 'IB Gateway ${{ matrix.channel }} ${{ steps.version.outputs.build_version }}' \ | |
-n 'IB Gateway ${{ matrix.channel }} ${{ steps.version.outputs.build_version }} release files' \ | |
ibgateway-* | |
- name: Update ${{ matrix.channel }} | |
if: ${{ steps.check-update.outputs.has_update == 'true' }} | |
run: ./update.sh ${{ matrix.channel }} ${{ steps.version.outputs.build_version }} | |
- name: Update README | |
if: ${{ steps.check-update.outputs.has_update == 'true' }} | |
run: | | |
# get stable and latest versions | |
export _stable_dockerfile='stable/Dockerfile' | |
export _latest_dockerfile='latest/Dockerfile' | |
if [ ${{ matrix.channel }} = 'latest' ]; then | |
# set latest | |
export LATEST_VERSION=${{ steps.version.outputs.build_version }} | |
export LATEST_MINOR=$(echo $LATEST_VERSION | cut -d '.' -f1,2) | |
# set stable | |
export STABLE_VERSION=$(grep 'ENV IB_GATEWAY_VERSION=' $_stable_dockerfile | head -1 | cut -d '=' -f2) | |
export STABLE_MINOR=$(echo $STABLE_VERSION| cut -d '.' -f1,2) | |
elif [ ${{ matrix.channel }} = 'stable' ]; then | |
# set STABLE | |
export STABLE_VERSION=${{ steps.version.outputs.build_version }} | |
export STABLE_MINOR=$(echo $STABLE_VERSION | cut -d '.' -f1,2) | |
# set LATEST | |
export LATEST_VERSION=$(grep 'ENV IB_GATEWAY_VERSION=' $_latest_dockerfile | head -1 | cut -d '=' -f2) | |
export LATEST_MINOR=$(echo $LATEST_VERSION| cut -d '.' -f1,2) | |
else | |
echo "invalid channel: ${{ matrix.channel }}" | |
exit 1 | |
fi | |
# IBC | |
export IBC_VERSION="$(grep 'ENV IBC_VERSION' Dockerfile.template|cut -d '=' -f 2)" | |
# show in log | |
echo "$LATEST_VERSION,$LATEST_MINOR,$STABLE_VERSION,$STABLE_MINOR,$IBC_VERSION" | |
# replace variables | |
envsubst '$LATEST_VERSION,$LATEST_MINOR,$STABLE_VERSION,$STABLE_MINOR,$IBC_VERSION' < template_README.md > README.md | |
- name: Create PR | |
if: ${{ steps.check-update.outputs.has_update == 'true' }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
t_branch='update-${{ matrix.channel }}-to-${{ steps.version.outputs.build_version }}' | |
git config user.name github-actions | |
git config user.email [email protected] | |
git pull | |
git checkout -b "$t_branch" origin/master | |
git add '${{ matrix.channel }}' README.md | |
git commit -m 'Update `${{ matrix.channel }}` to `${{ steps.version.outputs.build_version }}`' | |
git push --set-upstream origin "$t_branch" | |
gh pr create --base master --fill | |
build: | |
name: Call build workflow | |
needs: detect-release | |
if: needs.detect-release.outputs.update == 'true' | |
uses: gnzsnz/ib-gateway-docker/.github/workflows/build.yml@master | |
with: | |
channel: ${{ needs.detect-release.outputs.channel }} |