Skip to content

Commit

Permalink
ci: update release process with release-please
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov committed Jan 17, 2025
1 parent bb90831 commit 18e0352
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 169 deletions.
17 changes: 17 additions & 0 deletions .github/release-please/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"include-component-in-tag": false,
"release-type": "simple",
"packages": {
".": {
"component": "anvil-zksync",
"extra-files": [
{
"type": "generic",
"path": "Cargo.toml"
}
]
}
}
}
3 changes: 3 additions & 0 deletions .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.3"
}
77 changes: 36 additions & 41 deletions .github/workflows/build-push-docker.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,43 @@
name: Build and push Docker image

on:
workflow_call:
inputs:
tag:
type: string
description: 'The tag to use for the Docker image'
required: true
push:
branches:
- main
tags:
- "*"
pull_request:

env:
PLATFORMS: 'linux/amd64,linux/arm64'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
set-tags:
name: Set Docker Tags
runs-on: ubuntu-latest
outputs:
base_tag: ${{ steps.set_tag.outputs.base_tag }}
steps:
- uses: actions/checkout@v4

- name: Set Git SHA
id: git_sha
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Determine Base Tag
id: set_tag
run: |
ts=$(date +%s%N | cut -b1-13)
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "base_tag=${{ steps.git_sha.outputs.sha_short }}-${ts}" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "base_tag=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "base_tag=none" >> $GITHUB_OUTPUT
else
echo "Unsupported event ${GITHUB_EVENT_NAME} or ref ${GITHUB_REF}. Only refs/heads/main, refs/tags/*, and pull_request are supported."
exit 1
fi

build-push-image:
name: Build and Push Docker Image
runs-on: matterlabs-ci-runner-high-performance
needs: set-tags
env:
DOCKERHUB_IMAGE: us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync
steps:
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Login to GAR
- name: Determine Base Tag
id: set_tag
shell: 'bash -ex {0}'
run: |
gcloud auth configure-docker us-docker.pkg.dev -q
[ ! -z "${{ inputs.tag }}" ] && BASE_TAG="${{ inputs.tag }}" \
|| BASE_TAG="$(git rev-parse --short HEAD)-$(date +%s%N | cut -b1-13)"
echo "base_tag=${BASE_TAG}" >> "${GITHUB_OUTPUT}"
- name: Login to GAR
run: gcloud auth configure-docker us-docker.pkg.dev -q

- name: Login to GHCR
uses: docker/login-action@v3
Expand All @@ -63,19 +50,27 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
id: docker_build
uses: docker/build-push-action@v6
id: push
with:
context: .
push: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
platforms: 'linux/amd64,linux/arm64'
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}
us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}
ghcr.io/${{ github.repository }}:${{ steps.set_tag.outputs.base_tag }}
${{ env.DOCKERHUB_IMAGE }}:${{ steps.set_tag.outputs.base_tag }}
- name: Generate docker image attestation
if: ${{ inputs.tag != '' }}
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

- name: Print image digest to summary
run: |
echo "Image tags: ghcr.io/${{ github.repository_owner }}/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}" >> $GITHUB_STEP_SUMMARY
echo "Image tags: us-docker.pkg.dev/matterlabs-infra/matterlabs-docker/anvil-zksync:${{ needs.set-tags.outputs.base_tag }}" >> $GITHUB_STEP_SUMMARY
echo "Image tags: ghcr.io/${{ github.repository }}:${{ steps.set_tag.outputs.base_tag }}" >> "${GITHUB_STEP_SUMMARY}"
echo "Image tags: ${{ env.DOCKERHUB_IMAGE }}:${{ steps.set_tag.outputs.base_tag }}" >> "${GITHUB_STEP_SUMMARY}"
50 changes: 50 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release-please

# Give permissions to the release-please bot to open and update PRs
# and commit to PRs the repository to update Cargo.lock
permissions:
contents: write
pull-requests: write
id-token: write
attestations: write

# Run the workflow on push to the main branch and manually
on:
push:
branches:
- main
workflow_dispatch:

jobs:

# Prepare the release PR with changelog updates and create github releases
# Do not publish to crates.io or upgrade dependencies
release-please:
uses: matter-labs/zksync-ci-common/.github/workflows/release-please.yaml@v1
secrets:
slack_webhook: ${{ secrets.SLACK_WEBHOOK }}
gh_token: ${{ secrets.GITHUB_TOKEN }}
with:
config: '.github/release-please/config.json' # Specify the path to the configuration file
manifest: '.github/release-please/manifest.json' # Specify the path to the manifest file
update-cargo-lock: true # Update Cargo.lock file
publish-to-crates-io: false # Disable publishing to crates.io
upgrade-dependencies: false # Do not upgrade workspace dependencies

# Trigger workflow to publish binaries
release-binaries:
if: ${{ needs.release-please.outputs.releases_created == 'true' }}
needs: release-please
uses: ./.github/workflows/release.yml
with:
tag: ${{ needs.release-please.outputs.tag_name }}
secrets: inherit

# Trigger workflow to publish docker images
release-docker:
if: ${{ needs.release-please.outputs.releases_created == 'true' }}
needs: release-please
uses: ./.github/workflows/build-push-docker.yml
with:
tag: ${{ needs.release-please.outputs.tag_name }}
secrets: inherit
139 changes: 32 additions & 107 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
# This workflow is borrowed from reth, which is borrowed from Lighthouse:
# reth: https://github.com/paradigmxyz/reth/blob/500b0fac135fe07635d871d64467326599e2b27e/.github/workflows/release.yml
# lighthouse: https://github.com/sigp/lighthouse/blob/693886b94176faa4cb450f024696cb69cda2fe58/.github/workflows/release.yml

name: release
name: Release binaries

on:
push:
tags:
- v*
workflow_call:
inputs:
tag:
type: string
description: 'The tag to use for the Docker image'
required: true

env:
REPO_NAME: ${{ github.repository_owner }}/anvil-zksync
CARGO_TERM_COLOR: always
RUSTFLAGS: ""

jobs:
extract-version:
name: extract version
runs-on: ubuntu-latest
steps:
- name: Extract version
run: echo "VERSION=$(echo ${GITHUB_REF#refs/tags/})" >> $GITHUB_OUTPUT
id: extract_version
outputs:
VERSION: ${{ steps.extract_version.outputs.VERSION }}

build:
permissions:
id-token: write
attestations: write
name: build release
name: Build binaries
strategy:
matrix:
arch:
[
x86_64-unknown-linux-gnu,
aarch64-unknown-linux-gnu,
x86_64-apple-darwin,
aarch64-apple-darwin,
]
include:
- arch: x86_64-unknown-linux-gnu
platform: ubuntu-24.04
Expand All @@ -50,15 +26,17 @@ jobs:
platform: macos-latest

runs-on: ${{ matrix.platform }}
needs: [extract-version]
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}

- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Install target
run: rustup target add ${{ matrix.arch }}

Expand Down Expand Up @@ -86,12 +64,13 @@ jobs:
- name: Rename and move binary
run: |
mkdir artifacts
strip target/${{ matrix.arch }}/release/anvil-zksync
mv target/${{ matrix.arch }}/release/anvil-zksync ./artifacts
- name: Create artifacts
run: |
cd artifacts
tar -czf anvil-zksync-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.arch }}.tar.gz anvil-zksync*
tar -czf anvil-zksync-${{ inputs.tag }}-${{ matrix.arch }}.tar.gz anvil-zksync*
mv *tar.gz* ..
# =======================================================================
Expand All @@ -101,8 +80,8 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: anvil-zksync-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.arch }}.tar.gz
path: anvil-zksync-${{ needs.extract-version.outputs.VERSION }}-${{ matrix.arch }}.tar.gz
name: anvil-zksync-${{ matrix.arch }}
path: anvil-zksync-${{ inputs.tag }}-${{ matrix.arch }}.tar.gz

- name: Binaries attestation
uses: actions/attest-build-provenance@v2
Expand All @@ -111,87 +90,33 @@ jobs:

draft-release:
name: draft release
needs: [build, extract-version]
needs: build
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.extract-version.outputs.VERSION }}
permissions:
# Required to post the release
contents: write
steps:
# This is necessary for generating the changelog. It has to come before "Download Artifacts" or else it deletes the artifacts.
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ inputs.tag }}

# ==============================
# Download artifacts
# ==============================
- name: Download artifacts
uses: actions/download-artifact@v4

# ==============================
# Create release draft
# ==============================
- name: Generate full changelog
id: changelog
run: |
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$(git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 ${{ env.VERSION }}^)..${{ env.VERSION }})" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Generate list of contributors
id: contributors
run: |
echo "CONTRIBUTORS<<EOF" >> $GITHUB_OUTPUT
echo "$(git log --pretty=format:"- %aN (%aE)" $(git describe --tags --abbrev=0 ${{ env.VERSION }}^)..${{ env.VERSION }} | sort | uniq)" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create release draft
env:
GITHUB_USER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# The formatting here is borrowed from reth which borrowed it from Lighthouse (which is borrowed from OpenEthereum): https://github.com/openethereum/openethereum/blob/main/.github/workflows/build.yml
run: |
body=$(cat <<- "ENDBODY"
<!--Watch Release Notes video below 👇
[![YouTube Release Notes](https://img.youtube.com/vi/FZefCZW7JJk/0.jpg)](https://www.youtube.com/watch?v=FZefCZW7JJk)-->
## 📋 Summary
### 🐛 Bug Fixes:
- TBD
### ✨ New Features:
- TBD
### ⚠️ Breaking Changes:
- TBD
## 📜 All Changes
${{ steps.changelog.outputs.CHANGELOG }}
## ⭐ Contributors
${{ steps.contributors.outputs.CONTRIBUTORS }}
## 📥 Binaries
| System | Architecture | Binary |
|:---:|:---:|:---:|
| <img src="https://simpleicons.org/icons/linux.svg" style="width: 32px;"/> | x86_64 | [anvil-zksync-${{ env.VERSION }}-x86_64-unknown-linux-gnu.tar.gz](https://github.com/${{ env.REPO_NAME }}/releases/download/${{ env.VERSION }}/anvil-zksync-${{ env.VERSION }}-x86_64-unknown-linux-gnu.tar.gz) |
| <img src="https://simpleicons.org/icons/linux.svg" style="width: 32px;"/> | aarch64 | [anvil-zksync-${{ env.VERSION }}-aarch64-unknown-linux-gnu.tar.gz](https://github.com/${{ env.REPO_NAME }}/releases/download/${{ env.VERSION }}/anvil-zksync-${{ env.VERSION }}-aarch64-unknown-linux-gnu.tar.gz) |
| <img src="https://simpleicons.org/icons/apple.svg" style="width: 32px;"/> | x86_64 | [anvil-zksync-${{ env.VERSION }}-x86_64-apple-darwin.tar.gz](https://github.com/${{ env.REPO_NAME }}/releases/download/${{ env.VERSION }}/anvil-zksync-${{ env.VERSION }}-x86_64-apple-darwin.tar.gz) |
| <img src="https://simpleicons.org/icons/apple.svg" style="width: 32px;"/> | aarch64 | [anvil-zksync-${{ env.VERSION }}-aarch64-apple-darwin.tar.gz](https://github.com/${{ env.REPO_NAME }}/releases/download/${{ env.VERSION }}/anvil-zksync-${{ env.VERSION }}-aarch64-apple-darwin.tar.gz) |
| | | |
ENDBODY
)
assets=()
for asset in ./anvil-zksync-*.tar.gz*; do
assets+=("$asset/$asset")
done
tag_name="${{ env.VERSION }}"
echo "$body" | gh release create "$tag_name" "${assets[@]}" --draft -F "-" -t "Release: $tag_name"
with:
pattern: "anvil-zksync-*"
merge-multiple: 'false'

# - name: Create release draft
# env:
# GITHUB_USER: ${{ github.repository_owner }}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# assets=()
# for asset in ./anvil-zksync-*.tar.gz*; do
# assets+=("$asset/$asset")
# done
# tag_name="${{ env.VERSION }}"
# gh release create "$tag_name" "${assets[@]}" --draft -F "-" -t "Release: $tag_name"
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resolver = "2"
debug = 0

[workspace.package]
version = "0.2.4"
version = "0.2.4" # x-release-please-version
edition = "2021"
authors = ["The Matter Labs Team <[email protected]>"]
homepage = "https://zksync.io/"
Expand Down
Loading

0 comments on commit 18e0352

Please sign in to comment.