-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GH Actions Workflow for publishing new releases to BAR infra (#1918)
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Workflow for Beyond All Reaon, it only motifies BAR infra that a new engine | ||
# release was published. | ||
name: Publish Engine to BAR CDN | ||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
inputs: | ||
releaseId: | ||
description: Release Id as returned from GitHub Releases API | ||
required: true | ||
jobs: | ||
push: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: google-github-actions/auth@v2 | ||
id: auth | ||
with: | ||
project_id: 'bar-springfiles-syncer' | ||
workload_identity_provider: 'projects/741013749543/locations/global/workloadIdentityPools/github-actions/providers/github' | ||
create_credentials_file: false | ||
- uses: actions/github-script@v7 | ||
env: | ||
ACCESS_TOKEN: ${{ steps.auth.outputs.auth_token }} | ||
with: | ||
script: | | ||
const rel = await github.rest.repos.getRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: context.payload.release.id ?? context.payload.inputs.releaseId | ||
}); | ||
const engines = rel.data.assets | ||
.filter((a) => a.name.endsWith('64-minimal-portable.7z')) | ||
.map((a) => a.browser_download_url) | ||
.sort(); | ||
if (engines.length != 2 || !/linux/.test(engines[0]) || !/windows/.test(engines[1])) { | ||
throw new Error("Not found engine archives!"); | ||
} | ||
const msg = JSON.stringify({ | ||
category: "engine", | ||
linux64: { url: engines[0] }, | ||
windows64: { url: engines[1] }, | ||
}); | ||
const resp = await fetch("https://pubsub.googleapis.com/v1/projects/bar-springfiles-syncer/topics/cache-requests:publish", { | ||
method: 'POST', | ||
body: JSON.stringify({messages: [{ attributes: { "requestType": "SyncRequest"}, data: btoa(msg) }]}), | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": `Bearer ${process.env.ACCESS_TOKEN}` | ||
} | ||
}); | ||
if (!resp.ok) { | ||
throw new Error(`Failed to push message: ${resp.statusText}`); | ||
} |