Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joroshiba committed Feb 17, 2024
1 parent cc6e038 commit 7b54710
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ on:
# TODO: allow workflow dispatch to specify which binaries to build
workflow_dispatch:
inputs:
ref:
description: |
Fully qualified git ref which will be checked out and built. Defaults to using the branch workflow is run on.
Example: refs/tags/sequencer-v0.8.0 will then only build sequencer code at that tag.
tag:
description: Git branch, or tag to build from
required: false
push:
tags:
Expand All @@ -20,31 +18,31 @@ jobs:
uses: './.github/workflows/reusable-build.yml'
with:
package-name: 'cli'
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}

conductor:
uses: './.github/workflows/reusable-build.yml'
with:
package-name: 'conductor'
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}

composer:
uses: './.github/workflows/reusable-build.yml'
with:
package-name: 'composer'
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}

sequencer:
uses: './.github/workflows/reusable-build.yml'
with:
package-name: 'sequencer'
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}

relayer:
uses: './.github/workflows/reusable-build.yml'
with:
package-name: 'sequencer-relayer'
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}

build:
if: ${{ always() && !cancelled() }}
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ name: Docker
on:
workflow_dispatch:
inputs:
ref:
description: |
Fully qualified git ref which will be checked out and built. Defaults to using the branch workflow is run on.
Example: refs/tags/sequencer-v0.8.0 will then only build sequencer code at that tag.
tag:
description: Git branch, or tag to build from.
required: false
push:
branches:
Expand Down Expand Up @@ -38,7 +36,7 @@ jobs:
with:
package-name: composer
target-binary: astria-composer
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}
secrets: inherit

conductor:
Expand All @@ -48,7 +46,7 @@ jobs:
with:
package-name: conductor
target-binary: astria-conductor
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}
secrets: inherit

sequencer:
Expand All @@ -58,7 +56,7 @@ jobs:
with:
package-name: sequencer
target-binary: astria-sequencer
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}
secrets: inherit

sequencer-relayer:
Expand All @@ -68,7 +66,7 @@ jobs:
with:
package-name: sequencer-relayer
target-binary: astria-sequencer-relayer
git-ref: ${{ inputs.ref || github.ref }}
tag: ${{ inputs.tag }}
secrets: inherit

docker:
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/reusable-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ on:
package-name:
required: true
type: string
git-ref:
required: true
tag:
required: false
type: string

env:
REGISTRY: ghcr.io
FULL_REF: ${{ inputs.tag && format('refs/tags/{0}', inputs.tag) || github.ref }}

jobs:
upload-binaries:
if: startsWith(inputs.git-ref, format('refs/tags/{0}-v', inputs.package-name)) || github.event_name == 'workflow_dispatch'
if: startsWith(github.ref, format('refs/tags/{0}-v', inputs.package-name)) || !inputs.tag && github.event_name == 'workflow_dispatch' || startsWith(inputs.tag, inputs.package-name)
strategy:
matrix:
include:
Expand All @@ -32,17 +33,17 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.git-ref }}
ref: ${{ inputs.tag }}
- uses: dtolnay/[email protected]
- uses: arduino/setup-protoc@v2
with:
version: "24.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: taiki-e/upload-rust-binary-action@v1
with:
ref: ${{ inputs.git-ref }}
ref: ${{ env.FULL_REF }}
bin: astria-${{ inputs.package-name }}
dry-run: ${{ !startsWith(inputs.git-ref, format('refs/tags/{0}-v', inputs.package-name)) }}
dry-run: ${{ !startsWith(env.FULL_REF, format('refs/tags/{0}-v', inputs.package-name)) }}
# (optional) Target triple, default is host triple.
target: ${{ matrix.target }}
# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/reusable-docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
target-binary:
required: true
type: string
git-ref:
required: true
tag:
required: false
type: string
secrets:
DOCKER_TOKEN:
Expand All @@ -19,16 +19,17 @@ on:
required: true
env:
REGISTRY: ghcr.io
FULL_REF: ${{ inputs.tag && format('refs/tags/{0}', inputs.tag) || github.ref }}

jobs:
build-and-push:
runs-on: buildjet-8vcpu-ubuntu-2204
if: ${{ startsWith(inputs.git-ref, format('refs/tags/{0}-v', inputs.package-name)) || inputs.git-ref == 'refs/heads/main' || github.event_name == 'pull_request' }}
if: ${{ startsWith(inputs.tag, inputs.package-name) || startsWith(github.ref, format('refs/tags/{0}-v', inputs.package-name)) || github.ref == 'refs/heads/main' || github.ref == 'pull_request' }}
steps:
# Checking out the repo
- uses: actions/checkout@v3
with:
ref: ${{ inputs.git-ref }}
ref: ${{ inputs.tag }}
# https://github.com/docker/setup-qemu-action
- name: Login to Docker Hub
uses: docker/login-action@v2
Expand All @@ -55,10 +56,10 @@ jobs:
images: ${{ format('ghcr.io/astriaorg/{0}', inputs.package-name) }}
tags: |
type=ref,event=pr
type=match,pattern=refs/tags/([a-z-]+)-v(.*),group=2,enable=${{ startsWith('refs/tags/', inputs.git-ref) }},value=${{ inputs.git-ref }}
type=match,pattern=refs/tags/([a-z-]+)-v(.*),group=2,enable=${{ startsWith('refs/tags/', env.FULL_REF) }},value=${{ env.FULL_REF }}
type=sha
# set latest tag for `main` branch
type=raw,value=latest,enable=${{ inputs.git-ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest,enable=${{ env.FULL_REF == format('refs/heads/{0}', 'main') }}
- name: Build and push
uses: docker/build-push-action@v4
with:
Expand Down

0 comments on commit 7b54710

Please sign in to comment.