Skip to content

Commit

Permalink
Merge pull request #42 from pjbgf/push-artefacts
Browse files Browse the repository at this point in the history
build: Publish artefacts to the GH release
  • Loading branch information
pjbgf authored Jan 30, 2024
2 parents 0a0a3f6 + c70e750 commit 16cfd3d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- v*

permissions:
contents: read
contents: write # Upload artefacts to release.

jobs:
build:
Expand Down Expand Up @@ -35,3 +35,7 @@ jobs:
PRODUCTION_AWS_ACCESS_KEY_ID: ${{ secrets.PRODUCTION_AWS_ACCESS_KEY_ID }}
PRODUCTION_AWS_SECRET_ACCESS_KEY: ${{ secrets.PRODUCTION_AWS_SECRET_ACCESS_KEY }}
PRODUCTION_AWS_S3_BUCKET: ${{ secrets.PRODUCTION_AWS_S3_BUCKET }}

- run: make upload-gh
env:
GH_TOKEN: ${{ github.token }}
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ upload: $(AWSCLI) version ## uploads all artefacts from each policy into S3.
PRODUCTION_AWS_S3_BUCKET="$(PRODUCTION_AWS_S3_BUCKET)" \
./hack/upload

upload-gh: $(GH) ## upload all artefacts to the GitHub release.
$(MAKE) $(addsuffix -upload-gh, $(POLICIES))

%-upload-gh:
TAG=$(TAG) \
./hack/upload-gh $(subst :,/,$*)

version: ## parse and display version.
ifdef VERSION_MSG
@echo $(VERSION_MSG); exit 1
Expand Down
5 changes: 5 additions & 0 deletions hack/make/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ $(AWSCLI): ## Download awscliv2 if not yet downloaded.
curl "https://awscli.amazonaws.com/awscli-exe-linux-$(shell uname -m).zip" -o "$(TOOLS_BIN)/awscliv2.zip"
cd $(TOOLS_BIN) && unzip -q $(TOOLS_BIN)/awscliv2.zip
rm $(TOOLS_BIN)/awscliv2.zip

GH = $(shell which gh)
$(GH):
echo "GitHub CLI gh was not found. To install use your package manager."
exit 1
56 changes: 56 additions & 0 deletions hack/upload-gh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -eo pipefail

BASE_DIR="build"

function usage(){
echo "$0 <policy>"
exit 1
}

function check_input(){
policy=$1
if [[ ! -d "${BASE_DIR}/${policy}" ]]; then
echo "Policy ${policy} not found, run make build and try again."
exit 2
fi

[ -z "${TAG}" ] && echo "TAG is not set." && exit 1
return 0
}

function checksum_file(){
policy=$1

sumfile="${BASE_DIR}/${policy}/sha256sum-${policy}-noarch.txt"
echo -n "" > "${sumfile}"

files=$(ls build/"${policy}"/**/*.rpm)
for file in ${files}; do
sha256sum "${file}" | sed "s;$(dirname ${file})/;;g" >> "${sumfile}"
done

cat "${sumfile}"
}

function upload_files(){
policy=$1

files=("${BASE_DIR}/${policy}/sha256sum-${policy}-noarch.txt ")
files+=$(ls build/"${policy}"/**/*.rpm)

for file in ${files}; do
gh release upload ${TAG} $file
done
}

function main()
{
check_input "$1"
checksum_file "$1"
upload_files "$1"
}

[[ -z "$1" ]] && usage

main "$1"

0 comments on commit 16cfd3d

Please sign in to comment.