feat(ghpublish): choose (pre)release depending on tag ()

While there, include integration testing to make sure the script
is working as intended before using it.

While there, edit maketarball.bash's comments.
This commit is contained in:
Simone Basso 2022-09-03 12:11:19 +02:00 committed by GitHub
parent 7df25795c0
commit ae0613fbb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 6 deletions

18
.github/workflows/ghpublish.yml vendored Normal file

@ -0,0 +1,18 @@
# Verifies that `./script/ghpublish.bash` is WAI
name: ghpublish
on:
push:
branches:
- "release/**"
- "fullbuild"
- "ghpublishbuild"
jobs:
test_ghpublish_bash:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- run: ./script/ghpublish_test.bash

1
.gitignore vendored

@ -7,6 +7,7 @@
/DEBIAN_INSTALLED_PACKAGE.txt
/debops-ci
.DS_Store
/ghpublish.out.txt
/jafar
/*.jsonl
/miniooni

@ -0,0 +1,2 @@
gh release create -p rolling --target 7327e1ff7f0cfdc5ff0335574b85dc8ceb9465b6
gh release upload rolling --clobber ABC

@ -0,0 +1,2 @@
gh release create -p rolling --target 7327e1ff7f0cfdc5ff0335574b85dc8ceb9465b6
gh release upload rolling --clobber ABC

@ -0,0 +1,2 @@
gh release create -p v0.0.0-alpha --target 7327e1ff7f0cfdc5ff0335574b85dc8ceb9465b6
gh release upload v0.0.0-alpha --clobber ABC

@ -0,0 +1,2 @@
gh release create v0.0.0 --target 7327e1ff7f0cfdc5ff0335574b85dc8ceb9465b6
gh release upload v0.0.0 --clobber ABC

@ -16,10 +16,18 @@ else
__tag=rolling
fi
# 3. determine whether this is a pre-release
prerelease="-p"
if [[ $__tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
prerelease=""
fi
gh=${gh:-gh}
set -x
# 3. create the release as a pre-release unless it already exists
gh release create -p $__tag --target $GITHUB_SHA || true
# 4. create the release unless it already exists
$gh release create $prerelease $__tag --target $GITHUB_SHA || true
# 4. publish all the assets passed as arguments to the target release
gh release upload $__tag --clobber "$@"
# 5. publish all the assets passed as arguments to the target release
$gh release upload $__tag --clobber "$@"

32
script/ghpublish_test.bash Executable file

@ -0,0 +1,32 @@
#!/bin/bash
set -euxo pipefail
# Make sure we're not going to execute gh
export gh="echo gh"
# Use a very old SHA as target
export GITHUB_SHA="7327e1ff7f0cfdc5ff0335574b85dc8ceb9465b6"
# Test 1: make sure we're publishing to rolling as a
# pre-release when the build targets a branch
export GITHUB_REF="refs/heads/feature"
./script/ghpublish.bash ABC > ghpublish.out.txt
diff ./script/ghpublish-branch.out.txt ghpublish.out.txt
# Test 2: make sure we're publishing to rolling as a
# pre-release when the build target is a PR
export GITHUB_REF="refs/pull/123/merge"
./script/ghpublish.bash ABC > ghpublish.out.txt
diff ./script/ghpublish-pr.out.txt ghpublish.out.txt
# Test 3: make sure we're publishing to a pre-release when
# we're building a tag that is not a stable release.
export GITHUB_REF="refs/tags/v0.0.0-alpha"
./script/ghpublish.bash ABC > ghpublish.out.txt
diff ./script/ghpublish-prerelease.out.txt ghpublish.out.txt
# Test 3: make sure we're publishing to a release when
# we're building a tag that is a stable release.
export GITHUB_REF="refs/tags/v0.0.0"
./script/ghpublish.bash ABC > ghpublish.out.txt
diff ./script/ghpublish-release.out.txt ghpublish.out.txt

@ -10,7 +10,7 @@ if [[ $__ref == "" ]]; then
exit 1
fi
# 2. determine whether to publish to a release or to rolling
# 2. determine whether to use a release tag name or just "rolling"
if [[ $__ref =~ ^refs/tags/v ]]; then
__version=${__ref#refs/tags/v}
else
@ -25,4 +25,3 @@ set -x
# 4. generate the actual tarball
go mod vendor
tar -czf ooni-probe-cli-${__version}.tar.gz --transform "s,^,ooni-probe-cli-${__version}/," *