Skip to content

chore(ci): cleanup extra steps #1490

chore(ci): cleanup extra steps

chore(ci): cleanup extra steps #1490

Workflow file for this run

name: build-router
on:
push:
branches:
- main
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: write
contents: write
issues: read
checks: write
pull-requests: write
packages: write
id-token: write
env:
DOCKER_IMAGE_NAME: ghcr.io/graphql-hive/router
DOCKER_LICENSE: MIT
DOCKER_VENDOR: theguild
DOCKER_PLATFORMS: linux/amd64,linux/arm64
ZIG_VERSION: 0.15.1
BINARY_NAME: hive_router
jobs:
config:
name: check / config
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router/v'))
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: setup rust
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
- name: generate config schema
run: cargo router-config
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: generate documentation
working-directory: docs/generator
run: npm run generate
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload config artifact
with:
name: router-config.schema.json
path: router-config.schema.json
if-no-files-found: error
- name: Upload config to release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
if: ${{ github.event_name == 'release' }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: router-config.schema.json
asset_name: router-config.schema.json
tag: ${{ github.ref }}
- name: check config docs changes
run: git diff --exit-code ./docs/README.md
binary:
name: publish / binary / ${{ matrix.name }}
if: |
github.event_name == 'push' || github.event_name == 'pull_request' || (
github.event_name == 'release' &&
(
startsWith(github.event.release.tag_name, 'hive-router/v') ||
startsWith(github.event.release.tag_name, 'node-addon/v')
)
)
runs-on: ${{ matrix.action_runner }}
strategy:
matrix:
include:
- name: linux_arm64
rust_target: aarch64-unknown-linux-gnu
zigbuild: true
zigbuild_target: aarch64-unknown-linux-gnu.2.28
action_runner: ubuntu-latest
- name: linux_amd64
rust_target: x86_64-unknown-linux-gnu
zigbuild: true
zigbuild_target: x86_64-unknown-linux-gnu.2.28
action_runner: ubuntu-latest
- name: macos_arm64
zigbuild: false
rust_target: aarch64-apple-darwin
action_runner: macos-15
- name: macos_amd64
zigbuild: false
rust_target: x86_64-apple-darwin
action_runner: macos-15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
name: checkout
- name: setup rust (${{ matrix.rust_target }})
uses: actions-rust-lang/setup-rust-toolchain@1780873c7b576612439a134613cc4cc74ce5538c # v1
with:
target: ${{ matrix.rust_target }}
cache-key: ${{ matrix.name }}
# Only if using Zigbuild
- uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2
name: setup zig
if: ${{ matrix.zigbuild }}
with:
version: ${{ env.ZIG_VERSION }}
- run: cargo install cargo-zigbuild
name: install zigbuild
if: ${{ matrix.zigbuild }}
- name: zigbuild (${{ matrix.zigbuild_target }})
if: ${{ matrix.zigbuild }}
run: cargo zigbuild --release --target ${{ matrix.zigbuild_target }}
# Only if NOT using Zigbuild
- name: cargo build (${{ matrix.rust_target }})
run: cargo build --release --target ${{ matrix.rust_target }}
if: ${{ !matrix.zigbuild }}
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload router artifact
with:
name: hive_router_${{ matrix.name }}
path: |
target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
if-no-files-found: error
# napi build will use zigbuild when cross compiling
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: node-addon build (${{ matrix.rust_target }})
working-directory: lib/node-addon
env:
CROSS_COMPILE: ${{ matrix.zigbuild }}
TARGET: ${{ matrix.rust_target }}
run: npm run build
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
name: upload node addon artifact
with:
name: node_addon_${{ matrix.name }}
path: |
lib/node-addon/*.node
if-no-files-found: error
- name: Upload binaries to router release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'hive-router/v')
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.rust_target }}/release/${{ env.BINARY_NAME }}
asset_name: hive_router_${{ matrix.name }}
tag: ${{ github.ref }}
# NOTE: would publish from release.yaml but we need the artifacts. doing it from here is simpler
npm-publish:
name: publish / node-addon
runs-on: ubuntu-latest
needs:
- binary
if: github.event_name == 'release' && startsWith(github.event.release.tag_name, 'node-addon/v')
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: setup node
uses: the-guild-org/shared-config/setup@v1
with:
node-version-file: .node-version
- name: download node addon artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
pattern: node_addon_*
path: lib/node-addon
- name: prepare artifacts
working-directory: lib/node-addon
run: |
mv ./node_addon_linux_arm64/* .
mv ./node_addon_linux_amd64/* .
mv ./node_addon_macos_arm64/* .
mv ./node_addon_macos_amd64/* .
- name: publish
working-directory: lib/node-addon
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --provenance
- name: pack
working-directory: lib/node-addon
run: npm pack
- name: upload pack to release
uses: svenstaro/upload-release-action@6b7fa9f267e90b50a19fef07b3596790bb941741 # v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file_glob: true
file: lib/node-addon/*.tgz
tag: ${{ github.ref }}
docker:
name: build / docker
runs-on: ubuntu-latest
needs:
- binary
outputs:
docker_image_digest: ${{ steps.docker.outputs.digest }}
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: setup qemu
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: setup buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
- name: setup docker tags
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
labels: |
org.opencontainers.image.licenses=${{ env.DOCKER_LICENSE }}
org.opencontainers.image.vendor=${{ env.DOCKER_VENDOR }}
tags: |
type=ref,event=pr
type=semver,pattern={{version}},value=${{ github.event.release.name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=match,group=1,pattern=router/v(.*),value=${{ github.event.release.tag_name }},enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
type=sha
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
- name: download binary artifacts
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
with:
path: artifacts
pattern: hive_router_*
- name: prepare artifacts
run: |
mkdir -p ./target/linux/arm64
mkdir -p ./target/linux/amd64
mv ./artifacts/${{ env.BINARY_NAME }}_linux_arm64/${{ env.BINARY_NAME }} ./target/linux/arm64/${{ env.BINARY_NAME }}
mv ./artifacts/${{ env.BINARY_NAME }}_linux_amd64/${{ env.BINARY_NAME }} ./target/linux/amd64/${{ env.BINARY_NAME }}
ls -ltra ./target/linux/arm64/
ls -ltra ./target/linux/amd64/
- uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and push
id: docker
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
file: ./docker/router.Dockerfile
context: .
platforms: ${{ env.DOCKER_PLATFORMS }}
push: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || github.event_name == 'release' || github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: docker pr comment
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
with:
header: ${{ github.workflow }}
message: |
🐋 This PR was built and pushed to the following [Docker images](https://github.com/graphql-hive?ecosystem=container&tab=packages&visibility=public):
**Image Names**: `${{ env.DOCKER_IMAGE_NAME }}`
**Platforms**: `${{ env.DOCKER_PLATFORMS }}`
**Image Tags**: `${{ steps.meta.outputs.tags }}`
<details>
<summary>Docker metadata</summary>
```json
${{ steps.docker.outputs.metadata }}
```
</details>
test-docker-image:
name: test / docker
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
needs:
- docker
steps:
- name: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: run router image in background
run: |
echo "Docker image: ${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}"
docker run -d --name router -p 4000:4000 \
-e SUPERGRAPH_FILE_PATH="/app/supergraph.graphql" \
-v ./bench/supergraph.graphql:/app/supergraph.graphql \
${{ env.DOCKER_IMAGE_NAME }}@${{ needs.docker.outputs.docker_image_digest }}
sleep 5
- name: dump router logs
run: |
docker logs router
- name: test dummy request
run: |
TEST_RESPONSE=$(curl --fail -v -H "Content-Type: application/json" -d '{"query": "{ __typename }"}' http://localhost:4000/graphql)
echo $TEST_RESPONSE