Skip to content

Commit

Permalink
Add update Jaeger version workflow (#1200)
Browse files Browse the repository at this point in the history
* Add update Jaeger version workflow

* Incorporate Jaeger UI distributive
  • Loading branch information
kshmidt-digma authored Dec 12, 2024
1 parent b6549eb commit d67e74a
Show file tree
Hide file tree
Showing 14 changed files with 779 additions and 274 deletions.
34 changes: 14 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ on:
type: string
required: true
outputs:
dist-filename:
value: ${{ jobs.build.outputs.dist-filename }}
artifact-name:
value: ${{ jobs.build.outputs.artifact-name }}

jobs:
build:
runs-on: ubuntu-latest
outputs:
dist-filename: ${{ steps.get-dist-filename.outputs.dist_filename }}
artifact-name: ${{ steps.get-artifact-name.outputs.artifact_name }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand All @@ -23,28 +23,22 @@ jobs:
node-version-file: ".nvmrc"
cache: "npm"

- id: node-modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-node_modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-node_modules-
- if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- run: npm ci

- run: npm run build:prod:${{ inputs.platform }}

- name: Get distributive filename
id: get-dist-filename
- name: Get artifact name
id: get-artifact-name
run: |
FILENAME=$(ls dist/dist-*.zip | head -n 1 | xargs basename)
echo "DIST_FILENAME=$FILENAME" >> $GITHUB_ENV
echo "dist_filename=$FILENAME" >> $GITHUB_OUTPUT
git fetch --tags
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
NAME="dist-${{ inputs.platform }}-$LATEST_TAG"
echo "ARTIFACT_NAME=$NAME" >> $GITHUB_ENV
echo "artifact_name=$NAME" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.DIST_FILENAME }}
path: dist/${{ env.DIST_FILENAME }}
name: ${{ env.ARTIFACT_NAME }}
path: dist/
4 changes: 1 addition & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: ${{ inputs.dist-artifact-name }}
- run: |
mkdir -p dist
unzip -q ${{ inputs.dist-artifact-name }} -d dist
path: dist

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand Down
11 changes: 1 addition & 10 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ jobs:
node-version-file: ".nvmrc"
cache: "npm"

- id: node-modules-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-node_modules-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.setup-node.outputs.node-version }}-node_modules-
- if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci
- run: npm ci

- name: Lint
run: npm run lint
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Lint & test & build

on:
push:
branches: ["main"]
branches:
- "main"
# Github Actions don't support YAML anchors yet, so we have to repeat
# the paths-ignore in both push and pull_request events.
# More info: https://github.com/actions/runner/issues/1182
Expand All @@ -15,7 +16,8 @@ on:
- "LICENSE"
- "README.md"
pull_request:
branches: ["main"]
branches:
- "main"
paths-ignore:
- ".husky/**"
- ".vscode/**"
Expand Down Expand Up @@ -44,11 +46,11 @@ jobs:
with:
platform: "web"

build-test-docker-image:
build-docker-image:
name: Build Docker image
needs: [build-jetbrains, build-web]
uses: ./.github/workflows/docker-image.yml
secrets: inherit
with:
dist-artifact-name: ${{ needs.build-web.outputs.dist-filename }}
dist-artifact-name: ${{ needs.build-web.outputs.artifact-name }}
push: false
7 changes: 6 additions & 1 deletion .github/workflows/release-asset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: dist

- run: |
cd dist
zip -r ${{ inputs.artifact-name }}.zip *
- uses: softprops/action-gh-release@v2
with:
files: ${{ inputs.artifact-name }}
files: ${{ inputs.artifact-name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 36 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
with:
platform: "jetbrains"

attach-jetbrains-dist-asset:
name: Attach JetBrains release asset
attach-release-jetbrains-asset:
name: Attach release JetBrains asset
needs: build-jetbrains
uses: ./.github/workflows/release-asset.yml
with:
artifact-name: ${{ needs.build-jetbrains.outputs.dist-filename }}
artifact-name: ${{ needs.build-jetbrains.outputs.artifact-name }}

build-web:
name: Build for web
Expand All @@ -34,18 +34,47 @@ jobs:
with:
platform: "web"

attach-web-dist-asset:
name: Attach web release asset
attach-release-web-asset:
name: Attach release web asset
needs: build-web
uses: ./.github/workflows/release-asset.yml
with:
artifact-name: ${{ needs.build-web.outputs.dist-filename }}
artifact-name: ${{ needs.build-web.outputs.artifact-name }}

build-push-docker-image:
name: Build & push Docker image
needs: [build-jetbrains, build-web]
uses: ./.github/workflows/docker-image.yml
secrets: inherit
with:
dist-artifact-name: ${{ needs.build-web.outputs.dist-filename }}
dist-artifact-name: ${{ needs.build-web.outputs.artifact-name }}
push: true

update-digma:
name: Update version file in digma
needs:
[
attach-release-web-asset,
attach-release-jetbrains-asset,
build-push-docker-image
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get dependencies
run: |
DEPENDENCIES=$(cat dependencies.json | jq -c '.')
echo "DEPENDENCIES=$DEPENDENCIES" >> $GITHUB_ENV
- name: Create PR in digma-ui
run: |
curl -X POST -H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.RELEASE_PAT }}" \
https://api.github.com/repos/digma-ai/digma-ui/dispatches \
-d '{
"event_type": "update-ui-dependencies",
"client_payload": {
release: "'"${{ github.ref_name }}"'",
dependencies: '"${{ env.DEPENDENCIES }}"'
}
}'
29 changes: 29 additions & 0 deletions .github/workflows/update-jaeger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Update Jaeger version

on:
repository_dispatch:
types: [update-jaeger]

jobs:
update-jaeger:
runs-on: ubuntu-latest
env:
BRANCH_NAME: update-jaeger
JAEGER_FILENAME: jaeger.json
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.CONTENTS_WRITE_PAT }}

- name: Create or update version file
run: echo ${{ toJson(github.event.client_payload) }} > ${{ env.JAEGER_FILENAME }}

- name: Commit, push changes and create PR
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b ${{ env.BRANCH_NAME }}
git add ${{ env.JAEGER_FILENAME }}
git commit -m "Update Jaeger version"
git push origin ${{ env.BRANCH_NAME }}
gh pr create -t "Update Jaeger version" -B main -H ${{ env.BRANCH_NAME }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
coverage/
dist/
jaeger-ui/
node_modules/
storybook-static/
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ type AppData = Record<
export interface WebpackEnv {
WEBPACK_BUNDLE: true;
WEBPACK_BUILD: true;
app?: keyof typeof appData;
platform?: string;
compress?: boolean;
}
5 changes: 5 additions & 0 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jetBrainsPluginVersion": "2.0.403",
"jaegerUIVersion": "1.29.1-digma.1.0.0",
"jaegerVersion": "1.45.0"
}
100 changes: 100 additions & 0 deletions download-jaeger-ui.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable no-console */
import { Octokit } from "@octokit/rest";
import AdmZip from "adm-zip";
import fs from "fs";
import path from "path";
import dependenciesJson from "./dependencies.json" assert { type: "json" };

interface DependenciesJson {
jetBrainsPluginVersion: string;
jaegerUIVersion: string;
jaegerVersion: string;
}

interface DownloadReleaseAssetOptions {
owner: string;
repo: string;
tag: string;
assetName: string;
outputPath: string;
extractPath?: string;
}

// Get output path from command line arguments
let outputPath = "";
const outputArgIndex = process.argv.indexOf("--output");
if (outputArgIndex !== -1 && process.argv[outputArgIndex + 1]) {
outputPath = path.resolve(process.argv[outputArgIndex + 1]);
} else {
console.log("No output path provided.");
process.exit(1);
}

// Ensure the output directory exists
fs.mkdirSync(outputPath, { recursive: true });

const extractZip = (zipPath: string, extractPath: string) => {
const zip = new AdmZip(zipPath);
zip.extractAllTo(extractPath, true);
};

const downloadReleaseAsset = async ({
owner,
repo,
tag,
assetName,
outputPath,
extractPath
}: DownloadReleaseAssetOptions) => {
const octokit = new Octokit();

try {
const release = await octokit.rest.repos.getReleaseByTag({
owner,
repo,
tag
});

const asset = release.data.assets.find((a) => a.name === assetName);
if (!asset) {
console.error("GitHub release asset not found in release.");
return;
}

const response = await octokit.request(`GET ${asset.url}`, {
headers: {
Accept: "application/octet-stream"
}
});

const filePath = path.join(outputPath, assetName);
fs.writeFileSync(filePath, Buffer.from(response.data as string, "binary"));

if (extractPath) {
extractZip(filePath, extractPath);
}
} catch (error) {
console.error("Error downloading GitHub release asset:", error.message);
}
};

const jaegerUIVersion = (dependenciesJson as DependenciesJson).jaegerUIVersion;
const tag = `v${jaegerUIVersion}`;
const assetName = `dist-${tag}.zip`;
const extractPath = path.resolve(outputPath, "./dist");
const zipPath = path.join(outputPath, assetName);

if (fs.existsSync(zipPath)) {
console.log("Jaeger UI release asset already exists, skipping download...");
extractZip(zipPath, extractPath);
process.exit(0);
} else {
void downloadReleaseAsset({
owner: "digma-ai",
repo: "jaeger-ui",
tag,
assetName,
outputPath,
extractPath
});
}
Loading

0 comments on commit d67e74a

Please sign in to comment.