Skip to content

Commit

Permalink
feat: add release-please workflow (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbaliasnikov authored Jan 7, 2025
1 parent 4e70b33 commit bf21309
Show file tree
Hide file tree
Showing 3 changed files with 414 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/actions/publish-crates/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: 'Publish to crates.io'

description: 'Publishes Rust workspace to crates.io'

inputs:
workspace_path:
type: string
description: 'Path to the workspace to publish.'
default: '.'
required: false
org_owner:
type: string
description: 'Organization to add as owner of the crates.'
required: false
default: 'github:matter-labs:crates-io'
gh_token:
type: string
description: 'GitHub token to use for checking out the repository.'
required: true
run_build:
type: string
description: 'Whether to run build before release.'
required: false
default: 'true'
run_tests:
type: string
description: 'Whether to run tests before release.'
required: false
default: 'false'
cargo_registry_token:
type: string
description: 'Token to use for publishing to crates.io.'
required: true
slack_webhook:
type: string
description: 'Slack webhook to use for notifications.'
required: true


runs:
using: composite
steps:

- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ inputs.gh_token }}
submodules: "recursive"

- name: Install Rust toolchain
uses: moonrepo/setup-rust@v1
with:
bins: 'cargo-workspaces'

- name: Build the workspace before release
shell: 'bash -ex {0}'
if: ${{ inputs.run_build == true || inputs.run_build == 'true' }}
working-directory: ${{ inputs.workspace_path }}
run: cargo build

- name: Run tests before release
shell: 'bash -ex {0}'
if: ${{ inputs.run_tests == true || inputs.run_tests == 'true' }}
working-directory: ${{ inputs.workspace_path }}
run: cargo test

- name: Login to registry
shell: 'bash -ex {0}'
working-directory: ${{ inputs.workspace_path }}
run: cargo login ${{ inputs.cargo_registry_token }}

- name: Release packages to crates.io
shell: 'bash -ex {0}'
working-directory: ${{ inputs.workspace_path }}
run: cargo workspaces publish --publish-as-is

- name: Update ownership
shell: 'bash -ex {0}'
if: success() && inputs.org-owner != ''
working-directory: ${{ inputs.workspace_path }}
run: |
# Fail on error from pipe commands
set -o pipefail
ORG_OWNER=${{ inputs.org-owner }}
for PKG in $(cargo ws list); do
cargo owner --list --quiet ${PKG} | grep ${ORG_OWNER} || cargo owner --add ${ORG_OWNER} ${PKG}
done
- name: Slack notification
if: failure()
uses: matter-labs/zksync-ci-common/.github/actions/slack-notify-release@v1
with:
webhook: ${{ inputs.slack_webhook }}
context: 'Unable to publish to crates.io'
50 changes: 50 additions & 0 deletions .github/actions/slack-notify-release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Slack notification for failed workflow'

description: 'Send a Slack notification for failed workflow.'

inputs:
webhook:
description: 'Slack Incoming Webhook URL'
required: true
context:
description: 'The context of the workflow run'
required: false
default: ''

runs:
using: composite
steps:
- name: Slack failure notification
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ inputs.webhook }}
webhook-type: incoming-webhook
payload: |
blocks:
- type: "section"
text:
type: "mrkdwn"
text: "*🚨 GitHub Workflow Failed: ${{ inputs.context }}!*"
- type: "section"
fields:
- type: "mrkdwn"
text: "*Repository:*\n`${{ github.repository }}`"
- type: "mrkdwn"
text: "*Workflow:*\n`${{ github.workflow }}`"
- type: "mrkdwn"
text: "*Branch:*\n`${{ github.ref_name }}`"
- type: "mrkdwn"
text: "*Triggered By:*\n`${{ github.actor }}`"
- type: "section"
text:
type: "mrkdwn"
text: "You can view the detailed logs and troubleshoot the issue by visiting the link below:"
- type: "actions"
elements:
- type: "button"
text:
type: "plain_text"
text: "View Workflow Logs"
emoji: true
url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
style: "danger"
Loading

0 comments on commit bf21309

Please sign in to comment.