Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Use GitHub Actions to automatically publish releases (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
VJftw authored Oct 15, 2020
1 parent 323ff53 commit 698fa48
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 64 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Publish
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Install python dependencies
run: sudo apt-get update && sudo apt-get install -y python3-setuptools python3-pip

- name: Check out code
uses: actions/checkout@v2

- name: Please build
run: ./pleasew build //...

- name: Create pre-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./pleasew run //scripts:pre-release
20 changes: 5 additions & 15 deletions docs/contributers/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ We use annotated git tags to define a release by doing the following:
```
$ git tag --annotate <version>
e.g:
# git tag --annotate 0.1.0
# git tag --annotate v0.1.0
# then push the tags
$ git push --tags
```

This lets us use `git desribe` to give us a descriptive version from any commit in the format `<version>-<commits since version>-<short-sha>`, e.g.:

- `0.0.0` (when on the annotated commit (`git checkout 0.0.0`))
- `0.0.0-3-g7487887`
- `v0.0.0` (when on the annotated commit (`git checkout v0.0.0`))
- `v0.0.0-3-g7487887`

## Creating a Release

Expand All @@ -25,15 +25,5 @@ This lets us use `git desribe` to give us a descriptive version from any commit
git tag --annotate <version> --message "<version>"
git push origin --tags
```
2. Build and publish the release Docker images to Docker Hub by running:
```
# TODO(vj): make this script push image tags MAJOR and MINOR too. e.g. pushing tag `:0.1.2` should also push tags `:0` and `:0.1`
scripts/publish-images.sh <version>
# if this should be considered the "latest" version, push as the latest tag too:
scripts/publish-images.sh latest
```
3. Build the Dracon binary and publish it to GitHub releases by running:
```
scripts/publish-pre-release.sh
```
4. In the GitHub web interface, you can then promote the new pre-release to a release
2. Build and publish the release Docker images to Docker Hub by running `./pleasew run //scripts:publish-images`
3. In the GitHub web interface, you can then promote the new pre-release to a release
5 changes: 5 additions & 0 deletions scripts/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for script in glob(["*.sh"]):
sh_binary(
name=basename(splitext(script)[0]),
main=script,
)
48 changes: 23 additions & 25 deletions scripts/publish-pre-release.sh → scripts/pre-release.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#!/bin/bash -e
#!/bin/bash
set -euo pipefail

version=$(git describe --always)

echo "-> Enter your GitHub API Personal Access Token"
github_api_token=""
read -r -p "" github_api_token
# github_api_token=$(echo "${github_api_token}" | tr -d '[:space:]')

echo "-> Creating pre-release version: ${version}"
echo " Is this OK? (Ctrl+C to cancel, Enter to continue)"
read -p ""

plz build //cmd/dracon:dracon

github_api_version="application/vnd.github.v3+json"
github_owner="thought-machine"
github_repo="dracon"
Expand All @@ -31,7 +21,7 @@ EOF

release_resp=$(curl \
--header "Accept: ${github_api_version}" \
--header "Authorization: token ${github_api_token}" \
--header "Authorization: token ${GITHUB_TOKEN}" \
--silent \
--request POST \
--data "${post_release_json}" \
Expand All @@ -43,22 +33,30 @@ if [ -z "${release_id}" ] || [ "${release_id}" == "null" ]; then
echo "${release_resp}"
exit 1
fi

asset_resp=$(curl \
echo "-> created release ${release_id}"

assets=$(find plz-out/bin/cmd/dracon -executable -type f \( ! -iname ".*" ! -iname "*_test" \))
for asset in ${assets}; do
asset_name="${asset//plz-out\/bin\/cmd\//}"
asset_name=$(dirname "${asset_name}")
asset_name="${asset_name//\//_}"
asset_resp=$(curl \
--header "Accept: ${github_api_version}" \
--header "Authorization: token ${github_api_token}" \
--header "Authorization: token ${GITHUB_TOKEN}" \
--header "Content-Type: application/octet-stream" \
--silent \
--request POST \
--data-binary @"${PWD}/plz-out/bin/cmd/dracon/dracon" \
"https://uploads.github.com/repos/${github_owner}/${github_repo}/releases/${release_id}/assets?name=dracon")
asset_id=$(echo "${asset_resp}" | jq '.id')
if [ -z "${asset_id}" ] || [ "${asset_id}" == "null" ]; then
echo "!> could not find asset id in response"
echo "${asset_resp}"
exit 1
fi
--data-binary @"${asset}" \
"https://uploads.github.com/repos/${github_owner}/${github_repo}/releases/${release_id}/assets?name=${asset_name}")
asset_id=$(echo "${asset_resp}" | jq '.id')
if [ -z "${asset_id}" ] || [ "${asset_id}" == "null" ]; then
echo "!> could not find asset id in response"
echo "${asset_resp}"
exit 1
fi
echo "uploaded ${asset_name} to release ${release_id}"
done

echo ""
echo ""
echo "-> Created pre-release ${version} and uploaded dracon assets"
echo "-> Created pre-release ${version} and uploaded assets"
45 changes: 21 additions & 24 deletions scripts/publish-images.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/bin/bash -e
#!/bin/bash
set -eo pipefail

version="$1"

if [ -z "${version}" ]; then
echo "missing version"
exit 1
if [ -n "${DOCKERHUB_USERNAME}" ]; then
echo "${DOCKERHUB_PASSWORD}" | docker login --username "${DOCKERHUB_USERNAME}" --password-stdin
fi

# Build all images
plz query alltargets //... --include docker-build | sed 's/$/_load/g' | plz -p -v 2 --colour run sequential
version=$(git describe --always)

docker_rules=$(./pleasew query alltargets --include docker-build //...)

# Push image tags
plz query alltargets //... --include docker-build | sed 's/$/_push/g' | plz -p -v 2 --colour run sequential
fqns_to_push=()

# Get all image tags
plz query alltargets //... --include docker-build | sed 's/$/_fqn/g' | plz -p -v 2 --colour build
all_tag_files=$(find . -type f -name "*_fqn" -not -name '.target_*' | grep -v metadata)
all_tags=""
for tag_file in ${all_tag_files}; do
tag=$(cat ${tag_file})
all_tags+=" ${tag}"
export DOCKER_BUILDKIT=1
for rule in ${docker_rules}; do
./pleasew run "${rule}_load"
fqn=$(cat $(./pleasew build "${rule}_fqn" | tail -n1 | tr -s " "))
repo="$(echo "${fqn}" | cut -f1 -d\:)"
fqn_version="${repo}:${version}"
echo ""
echo "-> tagging as ${fqn_version}"
docker tag "${fqn}" "${fqn_version}"
fqns_to_push+=("${fqn_version}")
done

# Retag as version and push
for tag in ${all_tags}; do
repository=$(echo "${tag}" | cut -f1 -d":")
new_tag="${repository}:${version}"
docker tag "${tag}" "${new_tag}"
echo "tagged ${new_tag}"
docker push "${new_tag}"
for fqn_to_push in "${fqns_to_push[@]}"; do
echo "-> pushing as ${fqn_to_push}"
docker push "${fqn_to_push}"
done

0 comments on commit 698fa48

Please sign in to comment.