From 7eee3b6c729afc3cb0e0ccd204c7ae74d561b21c Mon Sep 17 00:00:00 2001 From: Ryan Moran Date: Mon, 11 May 2020 15:43:39 -0400 Subject: [PATCH] Adds .github workflows Includes: - running tests for PRs - creating a release with jam build artifacts --- .github/workflows/create-release.yml | 63 +++++++++++++++++++++++++ .github/workflows/test-pull-request.yml | 20 ++++++++ .gitignore | 1 + scripts/package.sh | 22 +++++++++ 4 files changed, 106 insertions(+) create mode 100644 .github/workflows/create-release.yml create mode 100644 .github/workflows/test-pull-request.yml create mode 100755 scripts/package.sh diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..e1f817b5 --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,63 @@ +name: Create Release + +on: + push: + branches: + - master + +jobs: + unit: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.14 + - name: Checkout + uses: actions/checkout@v2 + - name: Run Unit Tests + run: go test -v -count=1 ./... + + release: + name: Release + runs-on: ubuntu-latest + needs: unit + steps: + - name: Checkout + uses: actions/checkout@v2 + - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* + - name: Tag + id: tag + uses: paketo-buildpacks/github-config/actions/tag@master + - name: Package Jam + run : ./scripts/package.sh + - name: Create Release + id: create-release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag.outputs.tag }} + release_name: ${{ steps.tag.outputs.tag }} + draft: false + prerelease: false + - name: Upload Jam (darwin) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: build/jam-darwin + asset_name: ${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz + asset_content_type: application/octet-stream + - name: Upload Jam (linux) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create-release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: build/jam-linux + asset_name: ${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz + asset_content_type: application/octet-stream + diff --git a/.github/workflows/test-pull-request.yml b/.github/workflows/test-pull-request.yml new file mode 100644 index 00000000..92aa8288 --- /dev/null +++ b/.github/workflows/test-pull-request.yml @@ -0,0 +1,20 @@ +name: Test Pull Request + +on: + pull_request: + branches: + - master + +jobs: + unit: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Setup Go + uses: actions/setup-go@v1 + with: + go-version: 1.14 + - name: Checkout + uses: actions/checkout@v2 + - name: Run Unit Tests + run: go test -v -count=1 ./... diff --git a/.gitignore b/.gitignore index 4befed30..85e9b816 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store .idea +/build diff --git a/scripts/package.sh b/scripts/package.sh new file mode 100755 index 00000000..9a9f69f4 --- /dev/null +++ b/scripts/package.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e +set -u +set -o pipefail + +readonly ROOT_DIR="$(cd "$(dirname "${0}")/.." && pwd)" +readonly ARTIFACTS_DIR="${ROOT_DIR}/build" + +function main() { + mkdir -p "${ARTIFACTS_DIR}" + + pushd "${ROOT_DIR}" > /dev/null || return + for os in darwin linux; do + echo "* building jam on ${os}" + GOOS="${os}" GOARCH="amd64" go build -o "${ARTIFACTS_DIR}/jam-${os}" ./cargo/jam/main.go + chmod +x "${ARTIFACTS_DIR}/jam-${os}" + done + popd > /dev/null || return +} + +main "${@:-}"