Skip to content

Commit dc6f1f9

Browse files
authored
Merge pull request #3973 from element-hq/quenting/ci-reuse-actions
Refactor actions to reuse shared steps
2 parents 21bdf80 + 90bd12e commit dc6f1f9

20 files changed

+335
-275
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build the frontend assets
2+
description: Installs Node.js and builds the frontend assets from the frontend directory
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install Node
8+
uses: actions/setup-node@v4.2.0
9+
with:
10+
node-version: '22'
11+
12+
- name: Install dependencies
13+
run: npm ci
14+
working-directory: ./frontend
15+
shell: sh
16+
17+
- name: Build the frontend assets
18+
run: npm run build
19+
working-directory: ./frontend
20+
shell: sh
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Build the Open Policy Agent policies
2+
description: Installs OPA and builds the policies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Install Open Policy Agent
8+
uses: open-policy-agent/setup-opa@v2.2.0
9+
with:
10+
version: 0.70.0
11+
12+
- name: Build the policies
13+
run: make
14+
working-directory: ./policies
15+
shell: sh

.github/scripts/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
package-lock.json

.github/scripts/commit-and-tag.cjs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const fs = require("node:fs/promises");
11+
const { owner, repo } = context.repo;
12+
const version = process.env.VERSION;
13+
const parent = context.sha;
14+
if (!version) throw new Error("VERSION is not defined");
15+
16+
const files = [
17+
"Cargo.toml",
18+
"Cargo.lock",
19+
"tools/syn2mas/package.json",
20+
"tools/syn2mas/package-lock.json",
21+
];
22+
23+
/** @type {{path: string, mode: "100644", type: "blob", sha: string}[]} */
24+
const tree = [];
25+
for (const file of files) {
26+
const content = await fs.readFile(file);
27+
const blob = await github.rest.git.createBlob({
28+
owner,
29+
repo,
30+
content: content.toString("base64"),
31+
encoding: "base64",
32+
});
33+
console.log(`Created blob for ${file}:`, blob.data.url);
34+
35+
tree.push({
36+
path: file,
37+
mode: "100644",
38+
type: "blob",
39+
sha: blob.data.sha,
40+
});
41+
}
42+
43+
const treeObject = await github.rest.git.createTree({
44+
owner,
45+
repo,
46+
tree,
47+
base_tree: parent,
48+
});
49+
console.log("Created tree:", treeObject.data.url);
50+
51+
const commit = await github.rest.git.createCommit({
52+
owner,
53+
repo,
54+
message: version,
55+
parents: [parent],
56+
tree: treeObject.data.sha,
57+
});
58+
console.log("Created commit:", commit.data.url);
59+
60+
const tag = await github.rest.git.createTag({
61+
owner,
62+
repo,
63+
tag: `v${version}`,
64+
message: version,
65+
type: "commit",
66+
object: commit.data.sha,
67+
});
68+
console.log("Created tag:", tag.data.url);
69+
70+
return { commit: commit.data.sha, tag: tag.data.sha };
71+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const { owner, repo } = context.repo;
11+
const branch = process.env.BRANCH;
12+
const sha = process.env.SHA;
13+
if (!sha) throw new Error("SHA is not defined");
14+
15+
await github.rest.git.createRef({
16+
owner,
17+
repo,
18+
ref: `refs/heads/${branch}`,
19+
sha,
20+
});
21+
console.log(`Created branch ${branch} from ${sha}`);
22+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const { owner, repo } = context.repo;
11+
const version = process.env.VERSION;
12+
const tagSha = process.env.TAG_SHA;
13+
14+
if (!version) throw new Error("VERSION is not defined");
15+
if (!tagSha) throw new Error("TAG_SHA is not defined");
16+
17+
const tag = await github.rest.git.createRef({
18+
owner,
19+
repo,
20+
ref: `refs/tags/v${version}`,
21+
sha: tagSha,
22+
});
23+
console.log("Created tag ref:", tag.data.url);
24+
};

.github/scripts/merge-back.cjs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const { owner, repo } = context.repo;
11+
const sha = process.env.SHA;
12+
const branch = `ref-merge/${sha}`;
13+
if (!sha) throw new Error("SHA is not defined");
14+
15+
await github.rest.git.createRef({
16+
owner,
17+
repo,
18+
ref: `refs/heads/${branch}`,
19+
sha,
20+
});
21+
console.log(`Created branch ${branch} to ${sha}`);
22+
23+
// Create a PR to merge the branch back to main
24+
const pr = await github.rest.pulls.create({
25+
owner,
26+
repo,
27+
head: branch,
28+
base: "main",
29+
title: "Automatic merge back to main",
30+
body: "This pull request was automatically created by the release workflow. It merges the release branch back to main.",
31+
maintainer_can_modify: true,
32+
});
33+
console.log(
34+
`Created pull request #${pr.data.number} to merge the release branch back to main`,
35+
);
36+
console.log(`PR URL: ${pr.data.html_url}`);
37+
38+
// Add the `T-Task` label to the PR
39+
await github.rest.issues.addLabels({
40+
owner,
41+
repo,
42+
issue_number: pr.data.number,
43+
labels: ["T-Task"],
44+
});
45+
46+
// Enable auto-merge on the PR
47+
await github.graphql(
48+
`
49+
mutation AutoMerge($id: ID!) {
50+
enablePullRequestAutoMerge(input: {
51+
pullRequestId: $id,
52+
mergeMethod: MERGE,
53+
}) {
54+
clientMutationId
55+
}
56+
}
57+
`,
58+
{ id: pr.data.node_id },
59+
);
60+
};

.github/scripts/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"private": true,
3+
"devDependencies": {
4+
"@actions/github-script": "github:actions/github-script",
5+
"typescript": "^5.7.3"
6+
}
7+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const { owner, repo } = context.repo;
11+
const branch = process.env.BRANCH;
12+
const sha = process.env.SHA;
13+
if (!sha) throw new Error("SHA is not defined");
14+
15+
await github.rest.git.updateRef({
16+
owner,
17+
repo,
18+
ref: `heads/${branch}`,
19+
sha,
20+
});
21+
console.log(`Updated branch ${branch} to ${sha}`);
22+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only
4+
// Please see LICENSE in the repository root for full details.
5+
6+
// @ts-check
7+
8+
/** @param {import('@actions/github-script').AsyncFunctionArguments} AsyncFunctionArguments */
9+
module.exports = async ({ github, context }) => {
10+
const { owner, repo } = context.repo;
11+
const sha = context.sha;
12+
13+
const tag = await github.rest.git.updateRef({
14+
owner,
15+
repo,
16+
force: true,
17+
ref: "tags/unstable",
18+
sha,
19+
});
20+
console.log("Updated tag ref:", tag.data.url);
21+
};

0 commit comments

Comments
 (0)