Skip to content

Commit

Permalink
[v1] tag docker image matching serve-cli versions (#7374)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
enisdenjo and github-actions[bot] authored Jul 26, 2024
1 parent b815672 commit f427d7f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/@graphql-mesh_plugin-jwt-auth-7374-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-mesh/plugin-jwt-auth": patch
---
dependencies updates:
- Updated dependency [`@graphql-yoga/[email protected]` ↗︎](https://www.npmjs.com/package/@graphql-yoga/plugin-jwt/v/3.0.1) (from `3.0.0`, in `dependencies`)
59 changes: 59 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,62 @@ jobs:
secrets:
githubToken: ${{ secrets.GITHUB_TOKEN }}
npmToken: ${{ secrets.NODE_AUTH_TOKEN }}

ghcr:
runs-on: ubuntu-latest
needs: [release]
if: contains(needs.release.outputs.publishedPackages, '@graphql-mesh/serve-cli')
steps:
- name: version mesh-serve
uses: actions/github-script@v7
id: ver-mesh-serve
with:
result-encoding: string
script: |
const publishedPackages = ${{ needs.release.outputs.publishedPackages }};
const meshServe = publishedPackages.find((p) => p.name === '@graphql-mesh/serve-cli');
if (!meshServe) {
return core.setFailed('@graphql-mesh/serve-cli was not published!');
}
console.log(meshServe.version);
return meshServe.version;
- name: checkout
uses: actions/checkout@v4
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
- name: log in to ghcr
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: set up env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 18
packageManagerVersion: modern
- name: prepare
run: yarn prebuild
- name: bundle
run: yarn bundle
- name: inject mesh-serve version
run: |
yarn workspace @graphql-mesh/serve-cli inject-version ${{ steps.ver-mesh-serve.outputs.result }}
- name: bake and push
uses: docker/bake-action@v5
env:
MESH_SERVE_TAGS: ${{ steps.ver-mesh-serve.outputs.result }}
with:
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
push: true
- name: comment on pr
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Docker Images
message: |
Published images for this PR are available at:
```
ghcr.io/ardatan/mesh-serve:${{ steps.ver-mesh-serve.outputs.result }}
```
45 changes: 26 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,29 @@ jobs:
githubToken: ${{ secrets.GUILD_BOT_TOKEN }}
npmToken: ${{ secrets.NODE_AUTH_TOKEN }}

docker:
ghcr:
runs-on: ubuntu-latest
needs: [stable]
if: contains(needs.stable.outputs.publishedPackages, '@graphql-mesh/serve-cli')
steps:
- name: version mesh-serve
uses: actions/github-script@v7
id: ver-mesh-serve
with:
script: |
const publishedPackages = ${{ needs.stable.outputs.publishedPackages }};
const meshServe = publishedPackages.find((p) => p.name === '@graphql-mesh/serve-cli');
if (!meshServe) {
return core.setFailed('@graphql-mesh/serve-cli was not published!');
}
const { version } = meshServe;
const [major, minor] = version.split('.');
if (!major || !minor) {
return core.setFailed(`Unknown major or minor in version "${version}"!`);
}
const r = { version, tags: `latest,${major},${major}.${minor},${version}` };
console.log(r);
return r;
- name: checkout
uses: actions/checkout@v4
- name: set up docker buildx
Expand All @@ -36,7 +56,7 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: setup env
- name: set up env
uses: the-guild-org/shared-config/setup@main
with:
nodeVersion: 18
Expand All @@ -45,28 +65,15 @@ jobs:
run: yarn prebuild
- name: bundle
run: yarn bundle
- name: version
- name: inject mesh-serve version
run: |
export SHORT_REF="$(git rev-parse --short HEAD)"
echo SHORT_REF="$SHORT_REF" >> $GITHUB_ENV
export REF_NAME=$(echo "${{ github.head_ref || github.ref_name }}" | sed 's/\//_/g')
export VERSIONS="$SHORT_REF,$REF_NAME"
${{ github.ref == 'refs/heads/master' && 'export VERSIONS="$VERSIONS,latest"' || '' }}
echo VERSIONS="$VERSIONS" >> $GITHUB_ENV
yarn workspace @graphql-mesh/serve-cli inject-version ${{ fromJSON(steps.ver-mesh-serve.outputs.result).version }}
- name: bake and push
uses: docker/bake-action@v5
env:
MESH_SERVE_TAGS: ${{ fromJSON(steps.ver-mesh-serve.outputs.result).tags }}
with:
set: |
*.cache-from=type=gha
*.cache-to=type=gha,mode=max
push: true
- name: comment on pr
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Docker Images
message: |
Published images for this PR are available at:
```
ghcr.io/ardatan/mesh-serve:${{ env.SHORT_REF }}
```
4 changes: 2 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ group "default" {
targets = ["mesh-serve"]
}

variable "VERSIONS" {
variable "MESH_SERVE_TAGS" {
default = "dev"
}

target "mesh-serve" {
context = "packages/serve-cli"
platforms = ["linux/amd64", "linux/arm64"]
tags = formatlist("ghcr.io/ardatan/mesh-serve:%s", split(",", VERSIONS))
tags = formatlist("ghcr.io/ardatan/mesh-serve:%s", split(",", MESH_SERVE_TAGS))
annotations = [
"org.opencontainers.image.title=\"Mesh Serve\"",
"org.opencontainers.image.description=\"GraphQL Gateway by The Guild for anything-to-GraphQL\"",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
"copy-config-schema": "cp ./packages/legacy/types/src/config-schema.json ./packages/legacy/types/dist/esm && cp ./packages/legacy/types/src/config-schema.json ./packages/legacy/types/dist/cjs",
"fix-bin": "node scripts/fix-bin.js",
"generate-config-schema": "yarn graphql-to-config-schema --schema ./**/yaml-config.graphql --json ./packages/legacy/types/src/config-schema.json --typings ./packages/legacy/types/src/config.ts --markdown ./website/src/generated-markdown && yarn postgenerate-config-schema",
"inject-version": "yarn workspaces foreach -A run inject-version",
"lint": "cross-env \"ESLINT_USE_FLAT_CONFIG=false\" eslint --ext .ts \"./packages/**/src/**/*.ts\"",
"loadtest:e2e": "cross-env \"JEST=1\" \"E2E_TEST=true\" jest --no-watchman --runInBand --bail --config=jest.config.loadtest.js",
"postbuild": "yarn workspaces foreach -A run inject-version && yarn copy-config-schema && yarn fix-bin",
"postbuild": "yarn inject-version && yarn copy-config-schema && yarn fix-bin",
"postchangeset": "yarn install --no-immutable",
"postgenerate-config-schema": "node scripts/create-config-schema-ts.js && npx prettier --write ./packages/legacy/types/src",
"postinstall": "husky install && patch-package",
Expand Down
2 changes: 1 addition & 1 deletion packages/serve-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"typings": "dist/typings/index.d.ts",
"scripts": {
"bundle": "(rm -rf bundle || true) && rollup -c && yarn inject-version",
"bundle": "(rm -rf bundle || true) && rollup -c",
"inject-version": "tsx scripts/inject-version.ts"
},
"peerDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/serve-cli/scripts/inject-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { fileURLToPath, URL } from 'node:url';
// @ts-expect-error tsx will allow this to work
import { version } from '../package.json';
import pkg from '../package.json';

const version = process.argv[2] || pkg.version;

console.log(`Injecting version ${version} to build and bundle`);

Expand Down

0 comments on commit f427d7f

Please sign in to comment.