Skip to content

Commit

Permalink
Initial Github action workflows (#497)
Browse files Browse the repository at this point in the history
* Runs tests automatically
* Uploads release artifacts automatically
  • Loading branch information
ethack authored Sep 13, 2019
1 parent 6ea84cb commit eec0c46
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 10 deletions.
55 changes: 55 additions & 0 deletions .github/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# based on: https://github.com/skx/github-action-publish-binaries/blob/master/upload-script
#
# Upload binary artifacts when a new release is made.
#

set -e

# Ensure that the GITHUB_TOKEN secret is included
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

# Ensure that the file path is present
if [[ -z "$1" ]]; then
echo "Missing file (pattern) to upload."
exit 1
fi

# Only upload to non-draft releases
IS_DRAFT=$(jq --raw-output '.release.draft' $GITHUB_EVENT_PATH)
if [ "$IS_DRAFT" = true ]; then
echo "This is a draft, so nothing to do!"
exit 0
fi

# Run the build-script
make docker-build
docker container create --name rita quay.io/activecm/rita:latest
docker container cp rita:/rita ./rita

# Prepare the headers
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"

# Build the Upload URL from the various pieces
RELEASE_ID=$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)

# For each matching file
for file in $*; do
echo "Processing file ${file}"

FILENAME=$(basename ${file})
UPLOAD_URL="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
echo "$UPLOAD_URL"

# Upload the file
curl \
-sSL \
-XPOST \
-H "${AUTH_HEADER}" \
--upload-file "${file}" \
--header "Content-Type:application/octet-stream" \
"${UPLOAD_URL}"
done
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Upload files to new release

on:
release:
types: [published]

jobs:
upload:
name: Upload Artifacts
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v1
- run: .github/release.sh rita install.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Rita tests

on:
pull_request:
# Run tests except if only markdown files are changed
paths:
- '*'
- '!*.md'

jobs:
test:
name: static and unit tests
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@v1
- run: make docker-test

# integration:
# name: integration tests
# runs-on: ubuntu-16.04
# steps:
# - uses: actions/checkout@v1
# - run: |
# make docker-build-test
# docker container create --name rita --entrypoint /bin/sleep quay.io/activecm/rita:test 5m
# docker container start rita
# docker container exec rita tar cf vendor.tar vendor
# docker container cp rita:/go/src/github.com/activecm/rita/rita ./rita
# docker container cp rita:/go/src/github.com/activecm/rita/vendor.tar ./vendor.tar
# docker container stop rita
# tar xf vendor.tar
# - run: make integration-test
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ docker-build:
.PHONY: docker-build-test
docker-build-test:
docker build -t quay.io/activecm/rita:test -f test.Dockerfile .
docker run --rm quay.io/activecm/rita:test make

# Runs all tests inside docker container
.PHONY: docker-test
Expand Down
11 changes: 2 additions & 9 deletions docs/Releases.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Steps for creating a RITA release.
- Update the `install.sh` script so that the `_RITA_VERSION` variable reflects the desired version tag
- Create a branch with this change and go through the pull request process
- Ensure that all tests pass on this branch
- Note: after merging this pull request, the install script will break until you complete the rest of these steps since the installer will pull the binary file from the release page on Github, which are both yet to be created
- Note: after merging this pull request, the master install script will break until the release files are built and uploaded.

- Go to the [releases](https://github.com/activecm/rita/releases) page
- Click `Draft a new release` or pick the already existing draft
Expand All @@ -14,11 +14,4 @@ Steps for creating a RITA release.
- If the config file changed, give a thorough description of the needed changes
- Publish the release

- Wait for Quay.io to build the docker image
- [Use docker to create the build](https://github.com/activecm/rita/blob/master/docs/Docker%20Usage.md#using-docker-to-build-rita)
- Instead of `rita:master`, use `rita:[version]`

- Go back to the release you published
- Attach the following files:
- The `rita` binary, pulled from the docker image
- The `install.sh` file for the tagged code base
- Keep refreshing the release page until the `rita` binary and `install.sh` script are automatically added. You can keep an eye on the progress on the [actions page](https://github.com/activecm/rita/actions)

0 comments on commit eec0c46

Please sign in to comment.