Skip to content

Commit af0f8cc

Browse files
create deploy script and example project
1 parent fbb802b commit af0f8cc

File tree

5 files changed

+132
-2
lines changed

5 files changed

+132
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: bash-util-github-release
2+
3+
on:
4+
push
5+
6+
jobs:
7+
build-and-release:
8+
name: build and release
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: checkout
13+
uses: actions/[email protected]
14+
15+
- name: "build: create some release artifacts"
16+
run: |
17+
mkdir ./dist
18+
printf "dummy" >./dist/file1.zip
19+
printf "dummy" >./dist/file2.exe
20+
21+
- name: "deploy: create release and upload artifacts"
22+
run: ./github-release.sh
23+
env:
24+
GH_TOKEN: ${{ github.token }}

.gitignore

Whitespace-only changes.

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1-
# rs-util-github-release
2-
A tool for creating Github releases with artifacts.
1+
# bash-util-github-release
2+
3+
## What
4+
5+
An example project for creating Github releases with artifacts.
6+
7+
## How
8+
9+
1. Create a Github workflow that produces release assets in the dir `./dist`.
10+
2. Copy `github-release.sh` and run it as in the deploy-step of the example
11+
workflow.
12+
3. Trigger the workflow:
13+
14+
* **Pushing to a branch:**
15+
The script will create (or replace) a _nightly_ release.
16+
17+
* **Create a tag _tag name_ in git and push it to Github:**
18+
The script will create the respective _tag name_ release in Github.
19+
20+
* **Creating a release in Github:**
21+
The script will reuse the release created in Github.
22+
23+
In all cases the script uploads the asset files to the release.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {}
8+
}

github-release.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
fetch_tags() {
4+
git fetch --all --force --tags --prune-tags --prune
5+
}
6+
7+
create_release_nightly() {
8+
printf "create/replace release 'nightly' on branch %s\n" $GITHUB_REF_NAME
9+
10+
fetch_tags
11+
12+
RELEASE=nightly
13+
gh release delete \
14+
--cleanup-tag \
15+
--yes \
16+
$RELEASE \
17+
2>/dev/null || true
18+
19+
# Workaround for https://github.com/cli/cli/issues/8458
20+
printf "waiting for tag to be deleted\n"
21+
while fetch_tags; git tag -l | grep $RELEASE; do
22+
sleep 10;
23+
printf "still waiting...\n"
24+
done
25+
26+
fetch_tags
27+
28+
gh release create \
29+
--title "Nightly" \
30+
--notes "$(date +'%Y-%m-%d %H:%M:%S')" \
31+
--target $GITHUB_REF \
32+
--latest=false \
33+
$RELEASE
34+
35+
fetch_tags
36+
}
37+
38+
create_release_prod() {
39+
EXISTING=$(gh release list \
40+
--json tagName \
41+
--jq "[.[] | select(.tagName == \"$RELEASE\").tagName][0]")
42+
43+
if [[ -z $EXISTING ]]; then
44+
printf "create new release '%s'\n" $RELEASE
45+
gh release create \
46+
--title $RELEASE \
47+
--notes "$(date +'%Y-%m-%d %H:%M:%S')" \
48+
--verify-tag \
49+
$RELEASE
50+
else
51+
printf "use existing release '%s'\n" $RELEASE
52+
fi
53+
}
54+
55+
upload_artifacts() {
56+
printf "uploading artifacts to '%s'\n" $RELEASE
57+
58+
gh release upload --clobber $RELEASE $DISTDIR/*
59+
}
60+
61+
DISTDIR="./dist"
62+
63+
printf "verify github auth status:\n%s\n\n" "$(gh auth status)"
64+
65+
if [[ $GITHUB_REF_TYPE == 'tag' ]]; then
66+
RELEASE=$GITHUB_REF_NAME
67+
create_release_prod
68+
elif [[ $GITHUB_REF_TYPE == 'branch' ]]; then
69+
RELEASE="nightly"
70+
create_release_nightly
71+
fi
72+
73+
if [[ -e $DISTDIR ]]; then
74+
upload_artifacts
75+
else
76+
printf "no artifacts to upload\n"
77+
fi

0 commit comments

Comments
 (0)