-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Installs `semantic-release` in Github actions so it determines and tags the repo with every new `chainhook-cli` release. This also updates the `Cargo.toml` and `Cargo.lock` files automatically, but it doesn't yet update `chainhook-sdk` and `chainhook-types-rs` releases automatically. This also does not upload a new `chainhook-sdk` release to crates.io Related to #638
- Loading branch information
Showing
3 changed files
with
57 additions
and
76 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,40 +15,7 @@ concurrency: | |
cancel-in-progress: true | ||
|
||
jobs: | ||
|
||
get_release_info: | ||
name: Get Release Info | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tag: ${{ steps.new_release_tag.outputs.TAG }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get latest release | ||
if: startsWith(github.ref, 'refs/heads/main') | ||
id: release | ||
uses: pozetroninc/github-action-get-latest-release@master | ||
with: | ||
repository: ${{ github.repository }} | ||
excludes: prerelease, draft | ||
|
||
- name: Determine if release build | ||
if: startsWith(github.ref, 'refs/heads/main') | ||
id: new_release_tag | ||
env: | ||
LATEST_RELEASE: ${{ steps.release.outputs.release }} | ||
run: | | ||
CARGO_VERSION=v$(grep "version" components/chainhook-cli/Cargo.toml | head -n 1 | cut -d\" -f2) | ||
if [[ "${CARGO_VERSION}" != "${LATEST_RELEASE}" ]]; then | ||
echo "::set-output name=TAG::${CARGO_VERSION}" | ||
echo "::warning::Will create release for version: ${CARGO_VERSION}" | ||
else | ||
echo "::warning::Will not create a release" | ||
fi | ||
test: | ||
name: Generate test coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
|
@@ -65,7 +32,7 @@ jobs: | |
run: sudo apt-get install -y redis-server | ||
|
||
- name: Cache cargo | ||
uses: actions/cache@v3 | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
|
@@ -90,8 +57,7 @@ jobs: | |
token: ${{ secrets.CODECOV_TOKEN }} | ||
codecov_yml_path: .github/codecov.yml | ||
|
||
dist_chainhook: | ||
name: Build Chainhook Distributions | ||
distributions: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
|
@@ -145,7 +111,7 @@ jobs: | |
run: echo "RUST_VERSION_HASH=$(rustc --version | sha256sum | awk '{print $1}')" >> $GITHUB_ENV | ||
|
||
- name: Cache cargo | ||
uses: actions/cache@v3 | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.cargo/ | ||
|
@@ -273,65 +239,68 @@ jobs: | |
# Separate uploads to prevent paths from being preserved | ||
- name: Upload cargo artifacts (Linux) | ||
if: matrix.os != 'windows-latest' | ||
uses: actions/upload-artifact@v2 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: chainhook-${{ env.SHORT_TARGET_NAME }} | ||
path: chainhook-${{ env.SHORT_TARGET_NAME }}.tar.gz | ||
|
||
- name: Upload cargo artifact (Windows) | ||
if: matrix.os == 'windows-latest' | ||
uses: actions/upload-artifact@v2 | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: chainhook-${{ env.SHORT_TARGET_NAME }} | ||
path: chainhook-${{ env.SHORT_TARGET_NAME }}.msi | ||
|
||
release: | ||
name: Release | ||
semantic-release: | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != '' | ||
needs: | ||
- test | ||
- dist_chainhook | ||
- get_release_info | ||
permissions: | ||
actions: write | ||
contents: write | ||
- distributions | ||
outputs: | ||
new_release_version: ${{ steps.semantic.outputs.new_release_version }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Download pre-built dists | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4 | ||
|
||
- name: Tag and Release | ||
uses: ncipollo/release-action@v1 | ||
- name: Semantic Release | ||
uses: cycjimmy/semantic-release-action@v4 | ||
id: semantic | ||
# Only run on non-PR events or only PRs that aren't from forks | ||
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SEMANTIC_RELEASE_PACKAGE: ${{ github.event.repository.name }} | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_CRATES_IO_API_KEY }} | ||
with: | ||
artifacts: "**/*.tar.gz,**/*.msi" | ||
tag: ${{ needs.get_release_info.outputs.tag }} | ||
commit: ${{ env.GITHUB_SHA }} | ||
semantic_version: 19 | ||
extra_plugins: | | ||
@semantic-release/[email protected] | ||
@semantic-release/[email protected] | ||
@semantic-release/[email protected] | ||
[email protected] | ||
- name: Trigger pkg-version-bump workflow | ||
uses: peter-evans/repository-dispatch@v1 | ||
if: steps.semantic.outputs.new_release_version != '' | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
event-type: released | ||
client-payload: '{"tag": "${{ needs.get_release_info.outputs.tag }}"}' | ||
client-payload: '{"tag": "${{ steps.semantic.outputs.new_release_version }}"}' | ||
|
||
build-publish: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- test | ||
- dist_chainhook | ||
- get_release_info | ||
needs: semantic-release | ||
outputs: | ||
docker_image_digest: ${{ steps.docker_push.outputs.digest }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- name: Chainhook | ||
description: Chainhook is a reorg-aware indexing engine for the Stacks & Bitcoin blockchains. | ||
image: ${{ github.repository }} | ||
- image: ${{ github.repository }} | ||
artifact: chainhook-linux-x64-glibc | ||
dockerfile: dockerfiles/components/chainhook-node.dockerfile | ||
steps: | ||
|
@@ -340,11 +309,11 @@ jobs: | |
persist-credentials: false | ||
|
||
- name: Checkout tag | ||
if: needs.get_release_info.outputs.tag != '' | ||
if: needs.semantic-release.outputs.new_release_version != '' | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
ref: ${{ needs.get_release_info.outputs.tag }} | ||
ref: ${{ needs.semantic-release.outputs.new_release_version }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
@@ -358,8 +327,8 @@ jobs: | |
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}},value=${{ needs.get_release_info.outputs.tag }},enable=${{ needs.get_release_info.outputs.tag != '' }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ needs.get_release_info.outputs.tag }},enable=${{ needs.get_release_info.outputs.tag != '' }} | ||
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }} | ||
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }},enable=${{ needs.semantic-release.outputs.new_release_version != '' }} | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Log in to DockerHub | ||
|
@@ -369,7 +338,7 @@ jobs: | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Download pre-built dist | ||
uses: actions/download-artifact@v3 | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ${{ matrix.artifact }} | ||
|
||
|
@@ -387,7 +356,7 @@ jobs: | |
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks) | ||
push: ${{ (github.ref != 'refs/heads/main' || needs.get_release_info.outputs.tag != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} | ||
push: ${{ (github.ref != 'refs/heads/main' || needs.semantic-release.outputs.new_release_version != '') && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} | ||
|
||
deploy-dev: | ||
runs-on: ubuntu-latest | ||
|
@@ -418,10 +387,9 @@ jobs: | |
|
||
auto-approve-dev: | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.semantic-release.outputs.new_release_version != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
needs: | ||
- build-publish | ||
- get_release_info | ||
steps: | ||
- name: Approve pending deployments | ||
run: | | ||
|
@@ -462,11 +430,10 @@ jobs: | |
|
||
auto-approve-stg: | ||
runs-on: ubuntu-latest | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.semantic-release.outputs.new_release_version != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
needs: | ||
- build-publish | ||
- deploy-dev | ||
- get_release_info | ||
steps: | ||
- name: Approve pending deployments | ||
run: | | ||
|
@@ -484,8 +451,7 @@ jobs: | |
needs: | ||
- build-publish | ||
- deploy-staging | ||
- get_release_info | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.get_release_info.outputs.tag != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
if: startsWith(github.ref, 'refs/heads/main') && needs.semantic-release.outputs.new_release_version != '' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) | ||
env: | ||
DEPLOY_ENV: prd | ||
environment: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters