Skip to content

Commit 487d918

Browse files
authored
chore(release): adjust release pipeline (#549)
1 parent d099472 commit 487d918

File tree

4 files changed

+127
-61
lines changed

4 files changed

+127
-61
lines changed

.github/release-crates-check.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
echo "fetching workspace metadata from Cargo..."
7+
8+
METADATA=$(cargo metadata --format-version 1 --no-deps)
9+
10+
CRATES_TO_CHECK=$(echo "$METADATA" | jq -r '
11+
.workspace_members as $members | .packages[] |
12+
select(.id | IN($members[])) |
13+
select(.publish != []) |
14+
[.name, .version, .manifest_path] | @tsv
15+
')
16+
17+
if [ -z "$CRATES_TO_CHECK" ]; then
18+
echo "🤷 No publishable workspace crates found."
19+
exit 0
20+
fi
21+
22+
echo "---"
23+
24+
publish_list=""
25+
26+
while IFS=$'\t' read -r name version manifest_path; do
27+
echo "checking $name@$version (manifest: $manifest_path) ..."
28+
29+
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://crates.io/api/v1/crates/$name/$version")
30+
31+
if [ "$STATUS_CODE" -eq 200 ]; then
32+
echo " [x] ALREADY PUBLISHED"
33+
elif [ "$STATUS_CODE" -eq 404 ]; then
34+
echo " [ ] NOT PUBLISHED"
35+
dir_name=$(dirname "$manifest_path")
36+
publish_list="${publish_list}${name}\t${dir_name}\n"
37+
else
38+
echo " ❌ ERROR (Received HTTP $STATUS_CODE)" >&2
39+
fi
40+
echo "---"
41+
done <<< "$CRATES_TO_CHECK"
42+
43+
CRATES_TO_PUBLISH_JSON=$(echo -e "$publish_list" | jq -R -s '
44+
split("\n") | # Split the input string by newlines
45+
map(select(length > 0)) | # Remove any empty lines
46+
map(split("\t")) | # Split each line by the tab character
47+
map({key: .[0], value: .[1]}) | # Format as key-value pairs
48+
from_entries # Convert the array into an object
49+
')
50+
51+
echo "Crates to publish:"
52+
echo "$CRATES_TO_PUBLISH_JSON" | jq .
53+
54+
if [ -n "$GITHUB_OUTPUT" ]; then
55+
echo "Setting GitHub Actions output 'crates_to_publish'..."
56+
echo "crates_to_publish=$(echo "$CRATES_TO_PUBLISH_JSON" | jq -c .)" >> "$GITHUB_OUTPUT"
57+
echo "✅ GHA output set."
58+
fi

.github/workflows/build.yaml renamed to .github/workflows/build-router.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: build-router
22
on:
33
push:
44
branches:
@@ -31,7 +31,7 @@ env:
3131
jobs:
3232
config:
3333
runs-on: ubuntu-latest
34-
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router-v'))
34+
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'router/v'))
3535
steps:
3636
- name: checkout
3737
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
@@ -62,7 +62,7 @@ jobs:
6262

6363
binary:
6464
name: ${{ matrix.name }}
65-
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router-v'))
65+
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'router/v'))
6666
runs-on: ${{ matrix.action_runner }}
6767
strategy:
6868
matrix:
@@ -150,7 +150,7 @@ jobs:
150150
tags: |
151151
type=ref,event=pr
152152
type=semver,pattern={{version}},value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
153-
type=match,group=1,pattern=hive-router-v(.*),value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
153+
type=match,group=1,pattern=router/v(.*),value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
154154
type=sha
155155
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
156156
- name: download binary artifacts
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: release-crates
2+
3+
permissions:
4+
pull-requests: write
5+
contents: write
6+
id-token: write
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
13+
jobs:
14+
check:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
crates_to_publish: ${{ steps.check_crates.outputs.crates_to_publish }}
18+
steps:
19+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
20+
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
21+
with:
22+
cache: false
23+
- name: Run release-crates-check.sh
24+
id: check_crates
25+
run: |
26+
chmod +x ./.github/release-crates-check.sh
27+
./.github/release-crates-check.sh
28+
29+
publish-crates:
30+
name: crates
31+
runs-on: ubuntu-latest
32+
needs:
33+
- check
34+
if: ${{ github.repository_owner == 'graphql-hive' && needs.check.outputs.crates_to_publish != '{}' }}
35+
env:
36+
CRATES_TO_PUBLISH: ${{ fromJson(needs.check.outputs.crates_to_publish) }}
37+
steps:
38+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
39+
- uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
40+
with:
41+
cache: false
42+
- name: authenticate with crates.io
43+
uses: rust-lang/crates-io-auth-action@v1
44+
id: auth
45+
46+
- name: publish query-planner lib
47+
if: env.CRATES_TO_PUBLISH.hive-router-query-planner
48+
env:
49+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
50+
run: |
51+
cargo publish --manifest-path ${{ env.CRATES_TO_PUBLISH.hive-router-query-planner }}
52+
53+
- name: publish executor lib
54+
if: env.CRATES_TO_PUBLISH.hive-router-plan-executor
55+
env:
56+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
57+
run: |
58+
cargo publish --manifest-path ${{ env.CRATES_TO_PUBLISH.hive-router-plan-executor }}
59+
60+
- name: publish router lib
61+
if: env.CRATES_TO_PUBLISH.hive-router
62+
env:
63+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
64+
run: |
65+
cargo publish --manifest-path ${{ env.CRATES_TO_PUBLISH.hive-router }}

.github/workflows/release.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)