Skip to content
Snippets Groups Projects
Unverified Commit 670ec100 authored by Ryan Laurie's avatar Ryan Laurie Committed by GitHub
Browse files

Add alternative release channel info to version-info.json (#48153)

* allow updating version-info with other channel info

* polish + tests

* found the version swallower
parent b8516770
Branches
Tags
No related merge requests found
......@@ -314,11 +314,10 @@ jobs:
- name: Generate new version info
uses: actions/github-script@v7
id: new_version_info
if: ${{ inputs.tag_name }} == "latest"
with:
result-encoding: string
script: | # js
const { updateVersionInfoLatest } = require('${{ github.workspace }}/release/dist/index.cjs');
const { updateVersionInfoChannel } = require('${{ github.workspace }}/release/dist/index.cjs');
const fs = require('fs');
const edition = '${{ matrix.edition }}';
......@@ -327,15 +326,15 @@ jobs:
? '${{ needs.check-version.outputs.ee }}'
: '${{ needs.check-version.outputs.oss }}';
const newVersionInfo = await updateVersionInfoLatest({
newLatestVersion: canonical_version,
const newVersionInfo = await updateVersionInfoChannel({
channel: '${{ inputs.tag_name }}',
newVersion: canonical_version,
rollout: ${{ inputs.tag_rollout }},
});
fs.writeFileSync('version-info.json', JSON.stringify(newVersionInfo));
- name: Upload new version-info.json to S3
if: ${{ inputs.tag_name }} == "latest"
run: |
if [[ "${{ matrix.edition }}" == "ee" ]]; then
aws s3 cp version-info.json s3://${{ vars.AWS_S3_STATIC_BUCKET }}/version-info-ee.json
......@@ -343,7 +342,6 @@ jobs:
aws s3 cp version-info.json s3://${{ vars.AWS_S3_STATIC_BUCKET }}/version-info.json
fi
- name: Create cloudfront invalidation for version-info.json and version-info-ee.json
if: ${{ inputs.tag_name }} == "latest"
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ vars.AWS_CLOUDFRONT_STATIC_ID }} \
......
......@@ -651,7 +651,7 @@ jobs:
sparse-checkout: release
- name: Prepare build scripts
run: cd ${{ github.workspace }}/release && yarn && yarn build
- name: Publish release notes
- name: Publish version info
uses: actions/github-script@v7
id: new_version_info
with:
......
......@@ -35,9 +35,13 @@ export interface VersionInfo {
export interface VersionInfoFile {
latest: VersionInfo;
beta?: VersionInfo;
nightly?: VersionInfo;
older: VersionInfo[];
}
export type ReleaseChannel = "latest" | "beta" | "nightly";
export type Issue = {
number: number;
node_id: string;
......
......@@ -4,6 +4,7 @@ import _ from "underscore";
import { getMilestoneIssues } from "./github";
import type {
Issue,
ReleaseChannel,
ReleaseProps,
VersionInfo,
VersionInfoFile,
......@@ -52,6 +53,7 @@ export const generateVersionInfoJson = ({
const newVersionInfo = generateVersionInfo({ version, milestoneIssues });
return {
...existingVersionInfo,
latest: existingVersionInfo.latest,
older: [newVersionInfo, ...existingVersionInfo.older],
};
......@@ -100,6 +102,7 @@ export const updateVersionInfoLatestJson = ({
oldLatestVersionInfo.rollout = undefined;
return {
...existingVersionInfo,
latest: {
...newLatestVersionInfo,
rollout,
......@@ -142,24 +145,59 @@ export async function getVersionInfo({
return newVersionJson;
}
// for updating the latest version in version info
export const updateVersionInfoLatest = async ({
newLatestVersion,
// for updating the version in version info for a specific channel
export const updateVersionInfoChannel = async ({
channel,
newVersion,
rollout = 100,
}: {
newLatestVersion: string;
channel: ReleaseChannel;
newVersion: string;
rollout?: number;
}) => {
const url = getVersionInfoUrl(newLatestVersion);
const url = getVersionInfoUrl(newVersion);
const existingFile = (await fetch(url).then(r =>
r.json(),
)) as VersionInfoFile;
const newVersionJson = updateVersionInfoLatestJson({
newLatestVersion,
const newVersionJson = updateVersionInfoChannelJson({
channel,
version: newVersion,
existingVersionInfo: existingFile,
rollout,
});
return newVersionJson;
};
\ No newline at end of file
};
export function updateVersionInfoChannelJson({
existingVersionInfo,
channel,
version,
rollout = 100,
}: {
existingVersionInfo: VersionInfoFile;
channel: ReleaseChannel;
version: string;
rollout?: number;
}): VersionInfoFile {
if (channel === "latest") {
// tagging latest requires moving the current latest to the "older" array
return updateVersionInfoLatestJson({
newLatestVersion: version,
existingVersionInfo,
rollout,
});
}
// everything else is just setting the correct key in the version info
return {
...existingVersionInfo,
[channel]: {
version,
released: new Date().toISOString().slice(0, 10),
rollout,
highlights: [],
},
};
}
import type { Issue, VersionInfoFile } from "./types";
import { generateVersionInfoJson, getVersionInfoUrl, updateVersionInfoLatestJson } from "./version-info";
import { generateVersionInfoJson, getVersionInfoUrl, updateVersionInfoChannelJson, updateVersionInfoLatestJson } from "./version-info";
describe("version-info", () => {
describe("generateVersionInfoJson", () => {
......@@ -147,6 +147,8 @@ describe("version-info", () => {
});
expect(updatedJson.latest.version).toEqual("v0.2.5");
expect(updatedJson.beta).toEqual(oldJson.beta);
expect(updatedJson.nightly).toEqual(oldJson.nightly);
});
it("should ignore if version is already latest", () => {
......@@ -265,6 +267,114 @@ describe("version-info", () => {
});
});
describe("updateVersionInfoChannelJson", () => {
const oldJson = {
latest: {
version: "v0.2.4",
released: "2022-01-01",
patch: true,
highlights: ["Old Issue 1", "Old Issue 2"],
},
nightly: {
version: "v0.2.4.1",
released: "2022-01-03",
patch: true,
highlights: [],
},
beta: {
version: "v0.2.6",
released: "2022-01-02",
patch: true,
highlights: [],
},
older: [
{
version: "v0.2.5",
released: "2023-01-01",
patch: true,
highlights: ["New Issue 31", "New Issue 41"],
},
{
version: "v0.2.3",
released: "2021-01-01",
patch: true,
highlights: ["Old Issue 3", "Old Issue 4"],
},
{
version: "v0.2.2",
released: "2020-01-01",
patch: true,
highlights: ["Old Issue 5", "Old Issue 6"],
},
],
} as VersionInfoFile;
it("should update nightly version", () => {
const updatedJson = updateVersionInfoChannelJson({
version: "v0.2.4.2",
existingVersionInfo: oldJson,
channel: "nightly",
rollout: 51,
});
expect(updatedJson.nightly).toEqual({
version: "v0.2.4.2",
released: expect.any(String),
rollout: 51,
highlights: [],
});
expect(updatedJson.beta).toEqual(oldJson.beta);
expect(updatedJson.latest).toEqual(oldJson.latest);
});
it("should update beta version", () => {
const updatedJson = updateVersionInfoChannelJson({
version: "v0.2.7",
existingVersionInfo: oldJson,
channel: "beta",
rollout: 51,
});
expect(updatedJson.beta).toEqual({
version: "v0.2.7",
released: expect.any(String),
rollout: 51,
highlights: [],
});
expect(updatedJson.latest).toEqual(oldJson.latest);
expect(updatedJson.nightly).toEqual(oldJson.nightly);
});
it("should update latest version", () => {
const updatedJson = updateVersionInfoChannelJson({
version: "v0.2.5", // must be in the older array
existingVersionInfo: oldJson,
channel: "latest",
rollout: 51,
});
expect(updatedJson.latest).toEqual({
version: "v0.2.5",
released: expect.any(String),
rollout: 51,
patch: true,
highlights: ["New Issue 31", "New Issue 41"],
});
expect(updatedJson.older).toContainEqual({
version: "v0.2.4",
released: "2022-01-01",
patch: true,
highlights: ["Old Issue 1", "Old Issue 2"],
});
expect(updatedJson.beta).toEqual(oldJson.beta);
expect(updatedJson.nightly).toEqual(oldJson.nightly);
});
});
describe("getVersionInfoUrl", () => {
beforeEach(() => {
jest.resetModules();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment