1+ name : Trigger a release
2+ on :
3+ workflow_dispatch :
4+ secrets :
5+ BOT_GITHUB_TOKEN :
6+ required : true
7+ inputs :
8+ bump :
9+ type : choice
10+ description : " What semver bump to use for the release"
11+ required : true
12+ options :
13+ - " major"
14+ - " minor"
15+ - " patch"
16+ default : " minor"
17+
18+
19+ jobs :
20+ set-version :
21+ name : Bump version and push a tag
22+ runs-on : ubuntu-22.04
23+ permissions :
24+ contents : write
25+
26+ steps :
27+ - name : Checkout the code
28+ 29+
30+ - name : Install Rust toolchain
31+ run : |
32+ rustup toolchain install stable
33+ rustup default stable
34+
35+ - name : Install cargo-edit
36+ run : cargo install cargo-edit
37+
38+ - name : Bump version
39+ run : cargo set-version --workspace --bump=${{ github.event.inputs.bump }}
40+
41+ - name : Extract version
42+ id : version
43+ run : echo "version=v$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
44+
45+ - name : Commit and tag using the GitHub API
46+ 47+ id : commit
48+ env :
49+ VERSION : ${{ steps.version.outputs.version }}
50+ with :
51+ result-encoding : string
52+ # Commit & tag with the actions token, so that they get signed
53+ script : |
54+ const fs = require("fs/promises");
55+ const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
56+ const version = process.env.VERSION;
57+ const parent = context.sha;
58+ const cargoToml = await fs.readFile("Cargo.toml");
59+ const cargoTomlBlob = await octokit.rest.git.createBlob({
60+ owner,
61+ repo,
62+ content: cargoToml.toString("base64"),
63+ encoding: "base64",
64+ });
65+
66+ const cargoLock = await fs.readFile("Cargo.lock");
67+ const cargoLockBlob = await octokit.rest.git.createBlob({
68+ owner,
69+ repo,
70+ content: cargoLock.toString("base64"),
71+ encoding: "base64",
72+ });
73+
74+ const tree = await octokit.rest.git.createTree({
75+ owner,
76+ repo,
77+ tree: [{
78+ path: "Cargo.toml",
79+ mode: "100644",
80+ type: "blob",
81+ sha: cargoTomlBlob.data.sha,
82+ }, {
83+ path: "Cargo.lock",
84+ mode: "100644",
85+ type: "blob",
86+ sha: cargoLockBlob.data.sha,
87+ }],
88+ base_tree: parent,
89+ });
90+
91+ const commit = await octokit.rest.git.createCommit({
92+ owner,
93+ repo,
94+ message: version,
95+ parents: [parent],
96+ tree: tree.data.sha,
97+ });
98+
99+ await octokit.rest.git.createTag({
100+ owner,
101+ repo,
102+ tag: version,
103+ message: version,
104+ type: "commit",
105+ object: commit.data.sha,
106+ });
107+
108+ return commit.data.sha;
109+
110+ - name : Update the refs
111+ 112+ env :
113+ VERSION : ${{ steps.version.outputs.version }}
114+ COMMIT : ${{ steps.commit.outputs.result }}
115+ with :
116+ # Update the refs with the bot
117+ github-token : ${{ secrets.BOT_GITHUB_TOKEN }}
118+ script : |
119+ const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
120+ const version = process.env.VERSION;
121+ const commit = process.env.COMMIT;
122+ await octokit.rest.git.createRef({
123+ owner,
124+ repo,
125+ ref: `refs/tags/${version}`,
126+ sha: commit,
127+ });
128+
129+ await octokit.rest.git.updateRef({
130+ owner,
131+ repo,
132+ ref: "heads/main",
133+ sha: commit,
134+ });
0 commit comments