Skip to content

Commit

Permalink
feat: add release process (#125)
Browse files Browse the repository at this point in the history
Related to #12
  • Loading branch information
cgrindel authored Jan 10, 2023
1 parent 55056c1 commit e0f5024
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Create Release

on:
workflow_dispatch:
inputs:
release_tag:
required: true
type: string
reset_tag:
type: boolean
default: false
base_branch:
description: The branch being merged to.
type: string
default: main

jobs:
create_release:
runs-on: ubuntu-latest
env:
CC: clang

steps:

# Check out your code
- uses: actions/checkout@v2

# Generate a token that has permssions to create a release and create PRs.
- uses: tibdex/github-app-token@v1
id: generate_token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

# Configure the git user for the repository
- uses: cgrindel/gha_configure_git_user@v1

# Create the release
- uses: cgrindel/gha_create_release@v1
with:
release_tag: ${{ github.event.inputs.release_tag }}
reset_tag: ${{ github.event.inputs.reset_tag }}
base_branch: ${{ github.event.inputs.base_branch }}
github_token: ${{ steps.generate_token.outputs.token }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ workspace(name = "my_project")

# MARK: - swift_bazel

<!-- BEGIN WORKSPACE SNIPPET -->
http_archive(
name = "cgrindel_swift_bazel",
# See the README or release for the full declaration
Expand Down Expand Up @@ -133,6 +134,7 @@ load(
)

swift_rules_extra_dependencies()
<!-- END WORKSPACE SNIPPET -->
```

The above `WORKSPACE` boilerplate loads a file called `swift_deps.bzl`. The Gazelle plugin will
Expand Down
32 changes: 32 additions & 0 deletions release/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
load("@cgrindel_bazel_starlib//bzlformat:defs.bzl", "bzlformat_pkg")
load(
"@cgrindel_bazel_starlib//bzlrelease:defs.bzl",
"create_release",
"generate_release_notes",
"generate_workspace_snippet",
"update_readme",
)

bzlformat_pkg(name = "bzlformat")

# MARK: - Release

generate_workspace_snippet(
name = "generate_workspace_snippet",
template = "workspace_snippet.tmpl",
)

generate_release_notes(
name = "generate_release_notes",
generate_workspace_snippet = ":generate_workspace_snippet",
)

update_readme(
name = "update_readme",
generate_workspace_snippet = ":generate_workspace_snippet",
)

create_release(
name = "create",
workflow_name = "Create Release",
)
63 changes: 63 additions & 0 deletions release/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Release Process for `rules_spm`

The release process for this repository is implemented using GitHub Actions and the [bzlrelease
macros](https://github.com/cgrindel/bazel-starlib/tree/main/bzlrelease). This document describes how
to create a release.


## How to Create a Release

Once all of the code for a release has been merged to main, the release process can be started by
executing the `//release:create` target specifying the desired release tag (e.g. v1.2.3). To create
a release tagged with `v0.1.4`, one would run the following:

```sh
# Launch release GitHub Actions release workflow for v0.1.4
$ bazel run //release:create -- v0.1.4
```

This will launch the [release workflow](.github/workflows/create_release.yml). The workflow performs
the following steps:

1. Creates the specified tag at the HEAD of the main branch.
2. Generates release notes.
3. Creates a GitHub release.
4. Updates the `README.md` with the latest workspace snippet information.
5. Creates a PR with the updated `README.md` configured to auto-merge if all the checks pass.

There are two ways that this process could fail. First, if an improperly formatted release tag is
specified, the release workflow will fail. Be sure to prefix the release tag with `v`. Second, the
PR that contains the updates to the README.md file could fail if the PR cannot be automatically
merged.

## Other Scenarios

### Testing Changes to the Release Process

If you are testing changes to the release workflows, you should make the desired changes in a
branch, push the branch to `origin`, and then execute the `//release:create` target with the `--ref
<branch_name>`. For instance, if the remote branch name is `fixes_for_release` and the next release
is `v1.2.3`, then you would run the following:

```sh
$ bazel run //release:create -- v1.2.3 --ref fixes_for_release
```

### Rerunning a Failed Release

If you executed a release workflow and it failed without creating the release, you can rerun the
workflow with the same tag adding the `--reset_tag` option. For instance, if you need to rerun the
release for `v1.2.3`, you would run the following:

```sh
$ bazel run //release:create -- v1.2.3 --reset_tag
```

If the failure occurred after the creation of the release, you have two options:

1. Delete the release and run the release again with the `--reset_tag`; OR
2. Create a new release with a new tag.

One should be very careful with option #1 as clients may see the failed release and attempt to use
it. Option #2 is always the safest path.

54 changes: 54 additions & 0 deletions release/workspace_snippet.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

${http_archive_statement}

load("@cgrindel_swift_bazel//:deps.bzl", "swift_bazel_dependencies")

swift_bazel_dependencies()

load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")

bazel_starlib_dependencies()

# MARK: - Gazelle

# gazelle:repo bazel_gazelle

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
load("@cgrindel_swift_bazel//:go_deps.bzl", "swift_bazel_go_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

# Declare Go dependencies before calling go_rules_dependencies.
swift_bazel_go_dependencies()

go_rules_dependencies()

go_register_toolchains(version = "1.19.1")

gazelle_dependencies()

# MARK: - Swift Toolchain

http_archive(
name = "build_bazel_rules_swift",
# Populate with your preferred release
# https://github.com/bazelbuild/rules_swift/releases
)

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)
load("//:swift_deps.bzl", "swift_dependencies")

# gazelle:repository_macro swift_deps.bzl%swift_dependencies
swift_dependencies()

swift_rules_dependencies()

load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

0 comments on commit e0f5024

Please sign in to comment.