From 0c79117a0c504bf51fc11ccc2f2b9bc2a0b7f6b4 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 24 Sep 2018 15:42:16 -0400 Subject: [PATCH] add github-dev Signed-off-by: Jess Frazelle --- github-dev/Dockerfile | 10 ++++++++++ github-dev/upload-assets | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 github-dev/Dockerfile create mode 100755 github-dev/upload-assets diff --git a/github-dev/Dockerfile b/github-dev/Dockerfile new file mode 100644 index 0000000..b91a1d3 --- /dev/null +++ b/github-dev/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:alpine +MAINTAINER Jessica Frazelle + +RUN apk add --no-cache \ + bash \ + ca-certificates \ + curl \ + jq + +COPY upload-assets /usr/bin/upload-assets diff --git a/github-dev/upload-assets b/github-dev/upload-assets new file mode 100755 index 0000000..3885d68 --- /dev/null +++ b/github-dev/upload-assets @@ -0,0 +1,28 @@ +#!/bin/bash +set -e +set -o pipefail + +if [[ -z "$GITHUB_TOKEN" ]]; then + echo "Set the GITHUB_TOKEN env variable." + exit 1 +fi + +if [[ -z "$GITHUB_REPOSITORY" ]]; then + echo "Set the GITHUB_REPOSITORY env variable." + exit 1 +fi + +URI=https://api.github.com +API_VERSION=v3 +API_HEADER="Accept: application/vnd.github.${API_VERSION}+json" +AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" + +# Validate the GitHub token. +curl -o /dev/null -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" "${URI}/repos/${GITHUB_REPOSITORY}" || { echo "Error: Invalid repo, token or network issue!"; exit 1; } + +tag_response=$(curl -sSL -H "${AUTH_HEADER}" -H "${API_HEADER}" "${URI}/repos/${GITHUB_REPOSITORY}/releases/latest") + +tag_name=$(echo $tag_response | jq -e --raw-output .tag_name) +tag_id=$(echo $tag_response | jq -e --raw-output .id) + +echo "tag name: ${tag_name} tag id: ${tag_id}"