Push workflow (chrisleekr/binance-trading-bot)
The Push workflow from chrisleekr/binance-trading-bot, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Push workflow from the chrisleekr/binance-trading-bot repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Push
on: [push, workflow_dispatch]
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
lint-and-test:
name: Lint & Test
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- uses: actions/setup-node@v4
with:
node-version: 14
- name: Testing
run: |
npm install
npm run lint
npm run test
- name: Uploading test coverage
uses: codecov/codecov-action@v3
docker-images:
name: Build/Push development docker image
if:
github.repository == 'chrisleekr/binance-trading-bot' && github.ref ==
'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
# https://github.com/docker/setup-qemu-action#usage
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
# https://github.com/marketplace/actions/docker-setup-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# https://github.com/docker/login-action#docker-hub
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get build args
run: |
echo "PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut -c 3- | rev)" >> $GITHUB_ENV
echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# https://github.com/docker/build-push-action#multi-platform-image
- name: Build/Push development docker image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
target: production-stage
build-args: |
PACKAGE_VERSION=${{ env.PACKAGE_VERSION }}
GIT_HASH=${{ env.GIT_HASH }}
NODE_ENV=production
tags: |
chrisleekr/binance-trading-bot:development
# https://github.com/docker/build-push-action#multi-platform-image
- name: Build/Push development docker image - tradingview
uses: docker/build-push-action@v2
with:
context: ./tradingview
file: ./tradingview/Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
chrisleekr/binance-trading-bot:tradingview-development
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
name: Push on: [push, workflow_dispatch] concurrency: group: build-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true jobs: lint-and-test: timeout-minutes: 30 name: Lint & Test if: "!contains(github.event.head_commit.message, 'skip ci')" runs-on: latchkey-small steps: - name: Checkout source code uses: actions/checkout@v2 - uses: actions/setup-node@v4 with: cache: 'npm' node-version: 14 - name: Testing run: | npm install npm run lint npm run test - name: Uploading test coverage uses: codecov/codecov-action@v3 docker-images: timeout-minutes: 30 name: Build/Push development docker image if: github.repository == 'chrisleekr/binance-trading-bot' && github.ref == 'refs/heads/master' runs-on: latchkey-small steps: - name: Checkout code uses: actions/checkout@v2 # https://github.com/docker/setup-qemu-action#usage - name: Set up QEMU uses: docker/setup-qemu-action@v1 # https://github.com/marketplace/actions/docker-setup-buildx - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 # https://github.com/docker/login-action#docker-hub - name: Login to Docker Hub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Get build args run: | echo "PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut -c 3- | rev)" >> $GITHUB_ENV echo "GIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV # https://github.com/docker/build-push-action#multi-platform-image - name: Build/Push development docker image uses: docker/build-push-action@v2 with: context: . file: Dockerfile platforms: linux/amd64,linux/arm/v7,linux/arm64 push: true target: production-stage build-args: | PACKAGE_VERSION=${{ env.PACKAGE_VERSION }} GIT_HASH=${{ env.GIT_HASH }} NODE_ENV=production tags: | chrisleekr/binance-trading-bot:development # https://github.com/docker/build-push-action#multi-platform-image - name: Build/Push development docker image - tradingview uses: docker/build-push-action@v2 with: context: ./tradingview file: ./tradingview/Dockerfile platforms: linux/amd64,linux/arm/v7,linux/arm64 push: true tags: | chrisleekr/binance-trading-bot:tradingview-development
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
5 third-party actions are referenced by a movable tag. Pin them to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
What Latchkey heals here
This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:
- Dependency installs
- Container pulls and builds
This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.