|
| 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 | +}; |
0 commit comments