Skip to content

Commit

Permalink
CI: basic release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Dec 4, 2020
1 parent 345e85e commit 2b76e89
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Make release

on:
workflow_dispatch:
inputs:
sha:
description: "Commit SHA to create release from"
required: true
tag:
description: "Tag of the release"
required: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
ref: github.event.inputs.sha

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release
48 changes: 48 additions & 0 deletions ci/make_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os

import click
import git
import requests

ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
REPOSITORY = git.Repo(ROOT_DIR)


def send_github_event(workflow_name: str, token: str, inputs=()):
if inputs is None:
inputs = {}
payload = {"ref": "ci", "inputs": inputs}
headers = {"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"}
response = requests.post(
f"https://api.github.com/repos/it4innovations/rsds/actions/workflows/{workflow_name}/dispatches",
json=payload,
headers=headers)
response.raise_for_status()


token_option = click.option("-t", "--token", required=True, envvar="IR_GITHUB_TOKEN", show_envvar=True,
help="GitHub token. Note, it should have `repo` scope.")


@click.command(help="Create a new release")
@click.argument("branch")
@click.argument("tag")
@token_option
def make_release(branch: str, tag: str, token: str):
"""
Create a release using GitHub.
BRANCH is either a branch, commit or SHA from which to create the release.
TAG is the name of the release.
TOKEN is a Github token.
"""
sha = REPOSITORY.rev_parse(branch).hexsha
send_github_event("release.yml", token, {
"sha": sha,
"tag": tag
})


if __name__ == '__main__':
make_release()
3 changes: 3 additions & 0 deletions ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
click
requests
gitpython

0 comments on commit 2b76e89

Please sign in to comment.