Skip to content

Commit

Permalink
Make github release workflow create Release draft (#203)
Browse files Browse the repository at this point in the history
Make github release workflow create Release draft
  • Loading branch information
mzabani authored Sep 7, 2024
1 parent 337f137 commit 383d70d
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 43 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Create Github Release

on:
workflow_dispatch:
inputs:
versionToRelease:
description: 'A version to release with a leading `v` character, e.g. v0.1.5'
required: true

defaults:
run:
shell: bash # Implies `set -eo pipefail`, among other things. See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell

jobs:
create-github-release:
runs-on: ubuntu-22.04
environment: release

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

# We could use github artifacts, but it seems that it's not so trivial to use them across different workflows
# unless we use a third party action. So we just rely on Nix and our cachix cache.
- uses: cachix/install-nix-action@v24
with:
install_url: https://releases.nixos.org/nix/nix-2.8.1/install
nix_path: nixpkgs=channel:nixos-unstable
extra_nix_config: |
substituters = https://cache.nixos.org https://mzabani.cachix.org https://cache.iog.io
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= mzabani.cachix.org-1:wnkKakfl+rbT7zTtV1P1tAtjBTuh6GQVX7LfSd9sMbA= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
- uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Fetch all distributable artifacts from our Nix cache
run: |
# We don't want to build things all over again, so make sure they're in the cache with -j0
nix build -j0 -o results/codd-docker .#dockerImage.x86_64-linux
nix build -j0 -o results/codd-x86_64-linux ".#x86_64-unknown-linux-musl:codd:exe:codd"
nix build -j0 -o results/codd-aarch64-darwin .#coddDarwinAppBundle.aarch64-darwin
- name: Create Github Release Draft
env:
CREATE_GITHUB_RELEASE_ACCESS_TOKEN: ${{ secrets.CREATE_GITHUB_RELEASE_ACCESS_TOKEN }}
run: |
echo Creating draft release...
TAG="${{ github.event.inputs.versionToRelease }}"
# If the curl line below fails, one possibility is that the access token has expired.
# If that happens, generate a new Fine-grained personal access token at https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token
# Give it the "Contents" repository permissions (write), and then in codd's repository settings change the
# CREATE_GITHUB_RELEASE_ACCESS_TOKEN secret to the new token.
RELEASE_ID=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $CREATE_GITHUB_RELEASE_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/mzabani/codd/releases \
-d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"Description of the release. Please edit before publishing.\",\"draft\":true, \"generate_release_notes\": true}" | jq .id)
RELEASE_URL="https://uploads.github.com/repos/mzabani/codd/releases/$RELEASE_ID/assets"
echo Attaching aarch64-darwin zip bundle...
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $CREATE_GITHUB_RELEASE_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$RELEASE_URL?name=codd-aarch64-darwin.zip" \
--data-binary "@results/codd-aarch64-darwin/codd.zip"
echo Attaching x86_64-linux statically linked executable...
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $CREATE_GITHUB_RELEASE_ACCESS_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/octet-stream" \
"$RELEASE_URL?name=codd-x86_64-linux" \
--data-binary "@results/codd-x86_64-linux/bin/codd"
echo Draft release created
- name: Push to DockerHub
run: |
TAG="${{ github.event.inputs.versionToRelease }}"
docker load -i results/codd-docker
# Push both to the ref (tag name) and latest
docker tag codd:latest "mzabani/codd:$TAG"
docker tag codd:latest mzabani/codd:latest
docker push "mzabani/codd:$TAG"
docker push mzabani/codd:latest
- name: Instructions - README
run: |
echo <<EOF
A draft github release has been created at https://github.com/mzabani/codd/releases for you to edit and publish.
The docker image has already been published and tagged with the tag and as latest as well.
EOF
43 changes: 0 additions & 43 deletions .github/workflows/release.yml

This file was deleted.

0 comments on commit 383d70d

Please sign in to comment.