Skip to content

Commit

Permalink
chore: add workflow to create a release
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Jul 26, 2023
1 parent f0ce429 commit b8f4a59
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/version_bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: version_bump

jobs:
build:
name: version bump
runs-on: ubuntu-22.04
timeout-minutes: 30

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
RUSTC_FORCE_INCREMENTAL: 1

steps:
- name: Configure git
run: |
git config --global core.symlinks true
git config --global fetch.parallel 32
- name: Clone repository
uses: actions/checkout@v3
with:
token: ${{ secrets.DENOBOT_PAT }}
submodules: recursive

- uses: denoland/setup-deno@v1
- uses: dsherret/rust-toolchain-file@v1

- name: Create PR for release
env:
GITHUB_TOKEN: ${{ secrets.DENOBOT_PAT }}
GH_WORKFLOW_ACTOR: ${{ github.actor }}
run: |
git remote add upstream https://github.com/denoland/deno
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config user.name "${{ github.actor }}"
./tools/create_pr_for_release.ts
60 changes: 60 additions & 0 deletions tools/create_pr_for_release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env -S deno run -A --lock=tools/deno.lock.json
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { DenoWorkspace } from "./deno_core_workspace.ts";
import { $, createOctoKit, getGitHubRepository } from "./deps.ts";

const octoKit = createOctoKit();
const workspace = await DenoWorkspace.load();
const repo = workspace.repo;
const denoCoreCrate = workspace.getDenoCoreCrate();

// increment the core version
await denoCoreCrate.increment("minor");

// increment the dependency crate versions
for (const crate of workspace.getDenoCoreDependencyCrates()) {
await crate.increment("minor");
}

// update the lock file
await workspace.getDenoCoreCrate().cargoUpdate("--workspace");

const originalBranch = await repo.gitCurrentBranch();
const newBranchName = `release_${denoCoreCrate.version.replace(/\./, "_")}`;

// Create and push branch
$.logStep(`Creating branch ${newBranchName}...`);
await repo.gitBranch(newBranchName);
await repo.gitAdd();
await repo.gitCommit(denoCoreCrate.version);
$.logStep("Pushing branch...");
await repo.gitPush("-u", "origin", "HEAD");

// Open PR
$.logStep("Opening PR...");
const openedPr = await octoKit.request("POST /repos/{owner}/{repo}/pulls", {
...getGitHubRepository(),
base: originalBranch,
head: newBranchName,
draft: false,
title: denoCoreCrate.version,
body: getPrBody(),
});
$.log(`Opened PR at ${openedPr.data.url}`);

function getPrBody() {
let text = `Bumped versions for ${denoCoreCrate.version}\n\n` +
`Please ensure:\n` +
`- [ ] Crate versions are bumped correctly\n` +
`To make edits to this PR:\n` +
"```shell\n" +
`git fetch upstream ${newBranchName} && git checkout -b ${newBranchName} upstream/${newBranchName}\n` +
"```\n";

const actor = Deno.env.get("GH_WORKFLOW_ACTOR");
if (actor != null) {
text += `\ncc @${actor}`;
}

return text;
}
47 changes: 47 additions & 0 deletions tools/deno_core_workspace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

import { $, Repo } from "./deps.ts";

export class DenoWorkspace {
#repo: Repo;

static get rootDirPath() {
const currentDirPath = $.path.dirname($.path.fromFileUrl(import.meta.url));
return $.path.resolve(currentDirPath, "../");
}

static async load(): Promise<DenoWorkspace> {
return new DenoWorkspace(
await Repo.load({
name: "deno_core",
path: DenoWorkspace.rootDirPath,
}),
);
}

private constructor(repo: Repo) {
this.#repo = repo;
}

get repo() {
return this.#repo;
}

get crates() {
return this.#repo.crates;
}

/** Gets the deno_core dependency crates that should be published. */
getDenoCoreDependencyCrates() {
return this.getDenoCoreCrate()
.descendantDependenciesInRepo();
}

getDenoCoreCrate() {
return this.getCrate("deno_core");
}

getCrate(name: string) {
return this.#repo.getCrate(name);
}
}
4 changes: 4 additions & 0 deletions tools/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

export * from "https://raw.githubusercontent.com/denoland/automation/0.19.0/mod.ts";
export * from "https://raw.githubusercontent.com/denoland/automation/0.19.0/github_actions.ts";

0 comments on commit b8f4a59

Please sign in to comment.