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