Skip to content

Commit

Permalink
Simplifies the detection logic and adds github actions to auto-release
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt committed May 12, 2020
1 parent a311d39 commit 751e6ab
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 26 deletions.
14 changes: 14 additions & 0 deletions .github/util/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

function main() {
local previous tag
previous="$(git describe --tags "$(git rev-list --tags --max-count=1)")"
tag="$(printf "%s" "$previous" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')"

printf "v%s" "${tag#v}"
}

main "${@:-}"
94 changes: 94 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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: ./scripts/unit.sh

integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Run Integration Tests
run: ./scripts/integration.sh
env:
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}

release:
name: Release
runs-on: ubuntu-latest
needs: integration
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Tag
id: tag
run: |
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
TAG="$(./.github/util/tag.sh)"
echo "::set-output name=tag::$TAG"
- name: Package
env:
TAG: ${{ steps.tag.outputs.tag }}
run: PACKAGE_DIR=artifact ./scripts/package.sh --version "${TAG}" --archive
- name: Create Release Notes
id: create-release-notes
run: |
mkdir -p "${HOME}/bin"
export PATH="${PATH}:${HOME}/bin"
curl "https://github.com/cloudfoundry/packit/releases/download/v0.0.4/jam-linux" \
--silent \
--location \
--output "${HOME}/bin/jam"
chmod +x "${HOME}/bin/jam"
RELEASE_BODY=$(jam summarize --buildpack "${PWD}/artifact.tgz" --format markdown)
# Coz of this messed up issue
# https://github.community/t5/GitHub-Actions/set-output-Truncates-Multiline-Strings/m-p/38372#M3322
RELEASE_BODY="${RELEASE_BODY//'%'/'%25'}"
RELEASE_BODY="${RELEASE_BODY//$'\n'/'%0A'}"
RELEASE_BODY="${RELEASE_BODY//$'\r'/'%0D'}"
echo "::set-output name=release_body::$RELEASE_BODY"
- 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 }}
body: ${{ steps.create-release-notes.outputs.release_body }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
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: artifact.tgz
asset_name: ${{ github.event.repository.name }}-${{ steps.tag.outputs.tag }}.tgz
asset_content_type: application/gzip

37 changes: 37 additions & 0 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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: ./scripts/unit.sh

integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: unit
steps:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: Checkout
uses: actions/checkout@v2
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: Run Integration Tests
run: ./scripts/integration.sh
env:
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11 changes: 1 addition & 10 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ func Detect() packit.DetectFunc {
return packit.DetectResult{}, packit.Fail
}

return packit.DetectResult{
Plan: packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: "entrypoint"},
},
Requires: []packit.BuildPlanRequirement{
{Name: "entrypoint"},
},
},
}, nil
return packit.DetectResult{}, nil
}
}
13 changes: 2 additions & 11 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,12 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.WriteFile(filepath.Join(workingDir, "entrypoint.toml"), []byte(``), 0644)).To(Succeed())
})

it("returns a plan that provides and requires entrypoint", func() {
it("passes detection", func() {
result, err := detect(packit.DetectContext{
WorkingDir: workingDir,
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: "entrypoint"},
},
Requires: []packit.BuildPlanRequirement{
{
Name: "entrypoint",
},
},
}))
Expect(result.Plan).To(Equal(packit.BuildPlan{}))
})
})

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/cloudfoundry/dagger v0.0.0-20200507160821-634aab680698
github.com/cloudfoundry/occam v0.0.2
github.com/cloudfoundry/packit v0.0.6
github.com/cloudfoundry/packit v0.0.7
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/protobuf v1.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.10.0
github.com/paketo-buildpacks/occam v0.0.4
github.com/sclevine/spec v1.4.0
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ github.com/cloudfoundry/occam v0.0.2/go.mod h1:1zcSwIX+VVUMGuKBNL+XASI5G5eqnDa8c
github.com/cloudfoundry/packit v0.0.3/go.mod h1:9xu1MT6SrenSB4oFOXtruMapQ+vdfGXLzBZDnPjhYrM=
github.com/cloudfoundry/packit v0.0.6 h1:JQojVfWJDcxT2xX2pagWmUf0Jjate8f7HjFGBj2TH10=
github.com/cloudfoundry/packit v0.0.6/go.mod h1:9xu1MT6SrenSB4oFOXtruMapQ+vdfGXLzBZDnPjhYrM=
github.com/cloudfoundry/packit v0.0.7 h1:10j4d31TrJVCahe04A3bQ7QJUO3rpBLvQ+NGFXzg7os=
github.com/cloudfoundry/packit v0.0.7/go.mod h1:KCQ69DsYeruJQfZy2pxNR9ozg1OFKEYCFvUHl37t1+Q=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -126,6 +128,8 @@ github.com/onsi/gomega v1.9.0 h1:R1uwffexN6Pr340GtYRIdZmAiN4J+iw6WG4wog1DUXg=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.0 h1:Gwkk+PTu/nfOwNMtUB/mRUv0X7ewW5dO4AERT1ThVKo=
github.com/onsi/gomega v1.10.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/paketo-buildpacks/occam v0.0.4 h1:NFvufTzuKaPkOhir+Rl2F6OCS5cdSYklwy88To3ZE2o=
github.com/paketo-buildpacks/occam v0.0.4/go.mod h1:GNW2KzdEjWkcAJZj/aI+PSfXxGHkA8XxEkaUaCP5ttY=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
6 changes: 2 additions & 4 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import (
"time"

"github.com/cloudfoundry/dagger"
"github.com/cloudfoundry/occam"
"github.com/paketo-buildpacks/occam"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

. "github.com/onsi/gomega"
)

var (
buildpack string
)
var buildpack string

func TestIntegration(t *testing.T) {
Expect := NewWithT(t).Expect
Expand Down

0 comments on commit 751e6ab

Please sign in to comment.