Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Better release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Nov 2, 2023
1 parent 6d65bca commit c1e6ccd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 49 deletions.
105 changes: 63 additions & 42 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
description: "What semver bump to use for the release"
required: true
options:
- "prerelease"
- "premajor"
- "preminor"
- "major"
- "minor"
- "patch"
Expand All @@ -32,15 +35,24 @@ jobs:
rustup toolchain install stable
rustup default stable
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Extract the current version
id: current
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"

- name: Bump version
run: cargo set-version --workspace --bump=${{ github.event.inputs.bump }}
- name: Compute the new version
id: next
run: echo "version=$(npx --yes [email protected] -i "${{ github.event.inputs.bump }}" --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"

- 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: Set the crates version
run: |
sed -i "s/^package.version = .*/package.version = \"${{ steps.next.outputs.version }}\"/" Cargo.toml
- name: Run `cargo metadata` to make sure the lockfile is up to date
run: cargo metadata --format-version 1

- name: Set the tools/syn2mas version
working-directory: tools/syn2mas
run: npm version "${{ steps.next.outputs.version }}" --no-git-tag-version

- name: Commit and tag using the GitHub API
uses: actions/[email protected]
Expand All @@ -55,55 +67,59 @@ jobs:
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 files = [
"Cargo.toml",
"Cargo.lock",
"tools/syn2mas/package.json",
"tools/syn2mas/package-lock.json",
];
const tree = await github.rest.git.createTree({
owner,
repo,
tree: [{
path: "Cargo.toml",
mode: "100644",
type: "blob",
sha: cargoTomlBlob.data.sha,
}, {
path: "Cargo.lock",
const tree = [];
for (const file of files) {
const content = await fs.readFile(file);
const blob = await github.rest.git.createBlob({
owner,
repo,
content: content.toString("base64"),
encoding: "base64",
});
console.log(`Created blob for ${file}:`, blob.url);
tree.push({
path: file,
mode: "100644",
type: "blob",
sha: cargoLockBlob.data.sha,
}],
sha: blob.data.sha,
});
}
const treeObject = await github.rest.git.createTree({
owner,
repo,
tree,
base_tree: parent,
});
console.log("Created tree:", treeObject.url);
const commit = await github.rest.git.createCommit({
owner,
repo,
message: version,
parents: [parent],
tree: tree.data.sha,
tree: treeObject.data.sha,
});
console.log("Created commit:", commit.url);
await github.rest.git.createTag({
const tag = await github.rest.git.createTag({
owner,
repo,
tag: version,
tag: `v${version}`,
message: version,
type: "commit",
object: commit.data.sha,
});
console.log("Created tag:", tag.url);
return commit.data.sha;
Expand All @@ -112,23 +128,28 @@ jobs:
env:
VERSION: ${{ steps.version.outputs.version }}
COMMIT: ${{ steps.commit.outputs.result }}
BRANCH: ${{ github.event.inputs.target }}
with:
# Update the refs with the bot
# Update the refs with the bot token, so that workflows are triggered
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({
const branch = process.env.GITHUB_REF_NAME;
const tag = await github.rest.git.createRef({
owner,
repo,
ref: `refs/tags/${version}`,
ref: `refs/tags/v${version}`,
sha: commit,
});
console.log("Created tag ref:", tag.url);
await github.rest.git.updateRef({
const ref = await github.rest.git.updateRef({
owner,
repo,
ref: "heads/main",
ref: `heads/${branch}`,
sha: commit,
});
});
console.log("Updated branch ref:", ref.url);
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ default-members = ["crates/cli"]
members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.4.1"
license = "Apache-2.0"
authors = ["Quentin Gliech <[email protected]>"]
edition = "2021"
homepage = "https://matrix-org.github.io/matrix-authentication-service/"
repository = "https://github.com/matrix-org/matrix-authentication-service/"
# Updated in the CI with a `sed` command
package.version = "0.4.1"
package.license = "Apache-2.0"
package.authors = ["Quentin Gliech <[email protected]>"]
package.edition = "2021"
package.homepage = "https://matrix-org.github.io/matrix-authentication-service/"
package.repository = "https://github.com/matrix-org/matrix-authentication-service/"

[workspace.dependencies]

Expand Down

0 comments on commit c1e6ccd

Please sign in to comment.