Skip to content

Commit 599049d

Browse files
authored
chore(cli,sdk): update tag release workflow (#207)
1 parent 241bde9 commit 599049d

File tree

3 files changed

+163
-14
lines changed

3 files changed

+163
-14
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build Docker
2+
description: Builds the rex docker image
3+
4+
inputs:
5+
username:
6+
description: "Username for docker registry login"
7+
required: false
8+
password:
9+
description: "Password or token for docker registry login"
10+
required: false
11+
registry:
12+
description: "Docker registry to push the image to (if pushing)"
13+
required: false
14+
tags:
15+
description: "Comma-separated list of tags to apply to the built image"
16+
required: false
17+
default: "rex:ci"
18+
push:
19+
description: "Whether to push the built image to the registry"
20+
required: false
21+
default: "false"
22+
artifact_path:
23+
description: "The name of the artifact that is going to be pushed"
24+
required: false
25+
default: "rex_image.tar"
26+
build_args:
27+
description: "The arguments that are sent to the dockerfile to built. Format ARG=value"
28+
required: false
29+
default: ""
30+
31+
outputs:
32+
artifact_path:
33+
description: "The path of the image tar inside the action runner"
34+
value: ${{ steps.vars.outputs.artifact_path }}
35+
36+
runs:
37+
using: "composite"
38+
steps:
39+
- id: vars
40+
shell: bash
41+
run: |
42+
echo "artifact_path=/tmp/${{ inputs.artifact_path }}" >> $GITHUB_OUTPUT
43+
44+
- name: Login to Docker registry
45+
if: inputs.username != '' && inputs.password != ''
46+
uses: docker/login-action@v3
47+
with:
48+
registry: ${{ inputs.registry }}
49+
username: ${{ inputs.username }}
50+
password: ${{ inputs.password }}
51+
52+
- name: Set up Docker Buildx
53+
uses: docker/setup-buildx-action@v3
54+
55+
- name: Build Docker image
56+
uses: docker/build-push-action@v6
57+
with:
58+
context: .
59+
file: ./Dockerfile
60+
push: ${{ inputs.push }}
61+
tags: ${{ inputs.tags }}
62+
outputs: ${{ inputs.push == 'false' && format('type=docker,dest={0}', steps.vars.outputs.artifact_path) || '' }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
65+
build-args: ${{ inputs.build_args }}
66+
67+
# Since we're exporting the image as a tar, we need to load it manually as well
68+
- name: Load image locally
69+
shell: bash
70+
if: inputs.push == 'false'
71+
run: |
72+
docker load -i ${{ steps.vars.outputs.artifact_path }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "Free disk space"
2+
description: "Remove unneeded dependencies to free disk space"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Remove .NET
8+
shell: bash
9+
run: sudo rm -rf /usr/share/dotnet/
10+
11+
- name: Remove Android SDK
12+
shell: bash
13+
run: sudo rm -rf /usr/local/lib/android
14+
15+
- name: Remove Haskell
16+
shell: bash
17+
run: sudo rm -rf /opt/ghc /usr/local/.ghcup

.github/workflows/tag_release.yaml

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ name: Rex Release
22

33
on:
44
push:
5+
# On tags, this generates a release and pushes docker images with the tag name
56
tags:
6-
- "v[0-9]+.[0-9]+.[0-9]+-*"
7-
- "v[0-9]+.[0-9]+.[0-9]+"
7+
- "v*.*.*-*"
8+
# On pushes to main, this silently builds and pushes docker images tagged as 'main'
9+
branches:
10+
- main
11+
workflow_dispatch:
812

913
permissions:
1014
contents: write
1115
packages: write
16+
actions: write
1217

18+
env:
19+
REGISTRY: ghcr.io
20+
IMAGE_NAME: ${{ github.repository }}
21+
PROVER_REPRODUCIBLE_BUILD: true
1322

1423
jobs:
1524
build-rex:
@@ -34,25 +43,71 @@ jobs:
3443
- name: Checkout code
3544
uses: actions/checkout@v4
3645

37-
- name: Rustup toolchain install
38-
uses: dtolnay/rust-toolchain@master
39-
with:
40-
toolchain: ${{ vars.RUST_VERSION }}
46+
- name: Free Disk Space
47+
if: ${{ matrix.os == 'linux' }}
48+
uses: ./.github/actions/free-disk
49+
50+
- name: Setup Rust Environment
51+
uses: ./.github/actions/setup-rust
4152

4253
- name: Build rex
4354
run: |
4455
cargo build --release --bin rex
45-
mv target/release/rex rex-${{ matrix.os }}_${{ matrix.arch }}
56+
chmod +x target/release/rex
57+
mv target/release/rex rex-${{ matrix.os }}-${{ matrix.arch }}
4658
4759
- name: Upload artifact
4860
uses: actions/upload-artifact@v4
4961
with:
50-
name: rex-${{ matrix.os }}_${{ matrix.arch }}
51-
path: rex-${{ matrix.os }}_${{ matrix.arch }}
62+
name: rex-${{ matrix.os }}-${{ matrix.arch }}
63+
path: rex-${{ matrix.os }}-${{ matrix.arch }}
64+
65+
build-docker:
66+
name: "Build and publish rex docker image"
67+
runs-on: ubuntu-latest
5268

69+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
70+
permissions:
71+
contents: read
72+
packages: write
73+
attestations: write
74+
id-token: write
75+
actions: write
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v4
80+
81+
- name: Free Disk Space
82+
uses: ./.github/actions/free-disk
83+
84+
- name: Format name
85+
run: |
86+
# For branch builds (main) we want docker images tagged as 'main'. For tag pushes
87+
# use the tag name (stripped of a leading 'v').
88+
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
89+
echo "TAG_VERSION=main" >> $GITHUB_ENV
90+
else
91+
echo "TAG_VERSION=$(echo ${{ github.ref_name }} | tr -d v)" >> $GITHUB_ENV
92+
fi
93+
94+
# Pushes to ghcr.io/lambdaclass/rex
95+
- name: Build and push L1 Docker image
96+
id: push_l1
97+
uses: ./.github/actions/build-docker
98+
with:
99+
registry: ${{ env.REGISTRY }}
100+
username: ${{ github.actor }}
101+
password: ${{ secrets.GITHUB_TOKEN }}
102+
push: ${{ github.event_name != 'workflow_dispatch'}}
103+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG_VERSION }}
104+
105+
# Creates a release on GitHub with the binaries
53106
finalize-release:
107+
if: github.ref_type == 'tag' && github.event_name != 'workflow_dispatch'
54108
needs:
55109
- build-rex
110+
- build-docker
56111
runs-on: ubuntu-latest
57112
steps:
58113
- name: Checkout Code
@@ -68,9 +123,11 @@ jobs:
68123

69124
- name: Get previous tag
70125
run: |
71-
name=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | tail -2 | head -1)
72-
echo "PREVIOUS_TAG: $name"
73-
echo "PREVIOUS_TAG=$name" >> $GITHUB_ENV
126+
last_tag=$(git --no-pager tag --sort=creatordate | grep -v -E '^v[0-9]+\.[0-9]+\.[0-9]+-' | grep -v '${{ github.ref_name }}' | tail -1)
127+
echo "Last tag: $last_tag"
128+
common_parent=$(git merge-base ${{ github.ref_name }} $last_tag)
129+
echo "PREVIOUS_TAG: $common_parent"
130+
echo "PREVIOUS_TAG=$common_parent" >> $GITHUB_ENV
74131
75132
- name: Update CHANGELOG
76133
id: changelog
@@ -88,7 +145,10 @@ jobs:
88145
with:
89146
files: ./bin/**/*
90147
draft: false
91-
prerelease: false
148+
prerelease: true
92149
tag_name: ${{ github.ref_name }}
93150
name: "rex: ${{ github.ref_name }}"
94-
body: ${{ steps.changelog.outputs.changes }}
151+
body: >
152+
Installation and running instructions can be found in [our docs](https://github.com/lambdaclass/rex/blob/main/README.md).
153+
154+
${{ steps.changelog.outputs.changes }}

0 commit comments

Comments
 (0)