Skip to content

Commit

Permalink
Merge pull request #1 from pomerium/automate
Browse files Browse the repository at this point in the history
automate release
  • Loading branch information
calebdoxsey authored May 28, 2021
2 parents 58acbfc + f816145 commit 523c6c5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on: release

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Get tag name
id: tagName
run: |
TAG=${GITHUB_REF##*/}
echo ::set-output name=tag::${TAG}
- name: Checkout
uses: actions/checkout@v2

- name: Fetch
run: |
for _os in darwin linux ; do
for _arch in amd64 arm64 ; do
env PROMETHEUS_VERSION="${{ steps.tagName.outputs.tag }}" \
PROMETHEUS_OS="$_os" \
PROMETHEUS_ARCH="$_arch" \
./scripts/get-prometheus
done
done
- name: Upload
working-directory: bin
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload "${{ steps.tagName.outputs.tag }}" prometheus-*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
Empty file added bin/.gitkeep
Empty file.
49 changes: 49 additions & 0 deletions scripts/get-prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
set -euo pipefail

# require parameters
_os="${PROMETHEUS_OS:?"PROMETHEUS_OS is required"}"
_arch="${PROMETHEUS_ARCH:?"PROMETHEUS_ARCH is required"}"
_version="${PROMETHEUS_VERSION:?"PROMETHEUS_VERSION is required"}"

# helper functions
is_command() {
command -v "$1" >/dev/null
}

hash_sha256() {
TARGET=${1:-/dev/stdin}
if is_command gsha256sum; then
hash=$(gsha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command sha256sum; then
hash=$(sha256sum "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command shasum; then
hash=$(shasum -a 256 "$TARGET" 2>/dev/null) || return 1
echo "$hash" | cut -d ' ' -f 1
elif is_command openssl; then
hash=$(openssl -dst openssl dgst -sha256 "$TARGET") || return 1
echo "$hash" | cut -d ' ' -f a
else
echo "hash_sha256 unable to find command to compute sha-256 hash"
return 1
fi
}

# create a temporary directory
_wd="$(mktemp -d)"
function cleanup() {
rm -rf "$_wd"
}
trap cleanup EXIT

# download the release from github and save it to the working directory
_url="https://github.com/prometheus/prometheus/releases/download/${_version}/prometheus-${_version:1}.${_os}-${_arch}.tar.gz"
curl -L "$_url" | tar -xzf - -C "$_wd"

# move the binary to the bin folder and hash it
_src="$_wd/prometheus-${_version:1}.${_os}-${_arch}/prometheus"
_dst="./bin/prometheus-${_os}-${_arch}"
mv -f "$_src" "$_dst"
hash_sha256 "$_dst" >"$_dst.sha256"

0 comments on commit 523c6c5

Please sign in to comment.