From 3643bbbd0473a5ad039b7d79056a0312752d2b37 Mon Sep 17 00:00:00 2001 From: Alan Norton Date: Tue, 1 Feb 2022 12:09:43 -0500 Subject: [PATCH] devel-release and release via github actions (#297) * devel-release and release via github actions * junk paths during packaging * 1.17.6 * diff naming * clean up tests * cleanup consolidated test * store pointer to AppPool * remove test that was erroneously trying to boot puma under the hood --- .github/workflows/ci.yml | 42 ++++++++++++++++--- .github/workflows/release.yml | 37 +++++++++++++++++ .gitignore | 1 + Makefile | 28 +++++++------ dev/app.go | 1 + dev/app_test.go | 77 ----------------------------------- 6 files changed, 92 insertions(+), 94 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 dev/app_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a8cfcc..7f6a985 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,8 +8,7 @@ jobs: strategy: matrix: os: [macos-latest, macos-11.0, ubuntu-latest] - go-version: [1.17.2] - ruby-version: [3.1] + go-version: [1.17.6] name: ${{ matrix.os }} / go-${{ matrix.go-version }} steps: @@ -19,12 +18,12 @@ jobs: - uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby-version }} - - - uses: actions/checkout@v2 + ruby-version: 3 - run: gem install puma + - uses: actions/checkout@v2 + - if: contains(matrix.os, 'macos') run: | sw_vers @@ -35,3 +34,36 @@ jobs: - run: go mod download - run: go test -v -race -coverprofile=coverage.out -covermode=atomic -timeout=300s ./... + + devel-release: + runs-on: macos-latest + needs: test + + steps: + - uses: actions/setup-go@v1 + with: + go-version: 1.17.6 + + - run: go install github.com/mitchellh/gox@v1.0.2-0.20210311182516-8c3b2b9e647d + - run: echo $(go env GOPATH)/bin >> $GITHUB_PATH + + - uses: actions/checkout@v2 + + - run: make release + env: + RELEASE: ${{ env.GITHUB_SHA }} + + - uses: actions/upload-artifact@v2 + with: + name: puma-dev-${{ env.GITHUB_RUN_NUMBER }}-linux-amd64 + path: rel/linux_amd64/puma-dev + + - uses: actions/upload-artifact@v2 + with: + name: puma-dev-${{ env.GITHUB_RUN_NUMBER }}-darwin-amd64 + path: rel/darwin_amd64/puma-dev + + - uses: actions/upload-artifact@v2 + with: + name: puma-dev-${{ env.GITHUB_RUN_NUMBER }}-darwin-arm64 + path: rel/darwin_arm64/puma-dev diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1b5c04b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: release + +on: + push: + tags: + - 'v*' + +jobs: + release: + runs-on: macos-latest + + steps: + - uses: actions/setup-go@v1 + with: + go-version: 1.17.6 + + - run: go install github.com/mitchellh/gox@v1.0.2-0.20210311182516-8c3b2b9e647d + - run: echo $(go env GOPATH)/bin >> $GITHUB_PATH + + - name: get release version + id: get_version + run: echo ::set-output name=RELEASE_VERSION::${GITHUB_REF#refs/tags/v} + + - uses: actions/checkout@v2 + + - run: make release + env: + RELEASE: ${{ steps.get_version.outputs.RELEASE_VERSION }} + + - uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "pkg/*" + allowUpdates: true + omitBody: true + prerelease: true + removeArtifacts: true diff --git a/.gitignore b/.gitignore index 6687d7e..095dd21 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /bin/ /pkg/ +/rel/ /vendor/pkg/ /tmp /coverage*.out diff --git a/Makefile b/Makefile index 2bf5de9..83be1a7 100644 --- a/Makefile +++ b/Makefile @@ -10,24 +10,28 @@ install: lint: golangci-lint run + release: + rm -rf ./rel + mkdir ./rel + rm -rf ./pkg - mkdir -p ./pkg + mkdir ./pkg SDKROOT=$$(xcrun --sdk macosx --show-sdk-path) gox -cgo -os="darwin" -arch="amd64 arm64" -ldflags "-X main.Version=$$RELEASE" ./cmd/puma-dev gox -os="linux" -arch="amd64" -ldflags "-X main.Version=$$RELEASE" ./cmd/puma-dev - # linux - for arch in amd64; do \ - mv -v "puma-dev_linux_$$arch" puma-dev; \ - tar czvf "pkg/puma-dev-$$RELEASE-linux-$$arch.tar.gz" puma-dev; \ - done - - # macOS - for arch in amd64 arm64; do \ - mv -v "puma-dev_darwin_$$arch" puma-dev; \ - zip -v "pkg/puma-dev-$$RELEASE-darwin-$$arch.zip" puma-dev; \ - done + mkdir rel/linux_amd64 + mv -v puma-dev_linux_amd64 rel/linux_amd64/puma-dev + tar -C rel/linux_amd64 -cvzf "pkg/puma-dev-$$RELEASE-linux-amd64.tar.gz" puma-dev + + mkdir rel/darwin_amd64 + mv -v puma-dev_darwin_amd64 rel/darwin_amd64/puma-dev + zip -j -v "pkg/puma-dev-$$RELEASE-darwin-amd64.zip" rel/darwin_amd64/puma-dev + + mkdir rel/darwin_arm64 + mv -v puma-dev_darwin_arm64 rel/darwin_arm64/puma-dev + zip -j -v "pkg/puma-dev-$$RELEASE-darwin-arm64.zip" rel/darwin_arm64/puma-dev test: clean-test go test -v -race -coverprofile=coverage.out -covermode=atomic ./... diff --git a/dev/app.go b/dev/app.go index 1ecb3cc..955ddc6 100644 --- a/dev/app.go +++ b/dev/app.go @@ -451,6 +451,7 @@ func (a *AppPool) maybeIdle(app *App) bool { var ErrUnknownApp = errors.New("unknown app") +// Find an app by domain name. If the app is not running, launch it. func (a *AppPool) lookupApp(name string) (*App, error) { a.lock.Lock() defer a.lock.Unlock() diff --git a/dev/app_test.go b/dev/app_test.go deleted file mode 100644 index d2b203a..0000000 --- a/dev/app_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package dev - -import ( - "strings" - "testing" - - . "github.com/puma/puma-dev/dev/devtest" - "github.com/puma/puma-dev/homedir" - "github.com/stretchr/testify/assert" -) - -func TestAppPool_FindAppByDomainName_returnsAppWithExactName(t *testing.T) { - t.Skip("temp") - appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-exact-name-puma-dev") - testAppsToLink := map[string]string{ - "hipuma": "rack-hi-puma", - } - defer LinkTestApps(t, appLinkDir, testAppsToLink)() - - var events Events - - var testPool AppPool - testPool.Dir = appLinkDir - testPool.Events = &events - - app, err := testPool.FindAppByDomainName("hipuma") - if err != nil { - assert.Fail(t, err.Error()) - } - - assert.True(t, strings.HasPrefix(app.Name, "rack-hi-puma-")) -} - -func TestAppPool_FindAppByDomainName_returnsAppWithExactSubdomain(t *testing.T) { - t.Skip("temp") - appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-exact-subdomain-puma-dev") - testAppsToLink := map[string]string{ - "hipuma": "rack-hi-puma", - "foo.hipuma": "static-hi-puma", - } - defer LinkTestApps(t, appLinkDir, testAppsToLink)() - - var events Events - - var testPool AppPool - testPool.Dir = appLinkDir - testPool.Events = &events - - app, err := testPool.FindAppByDomainName("foo.hipuma") - if err != nil { - assert.Fail(t, err.Error()) - } - - assert.True(t, strings.HasPrefix(app.Name, "static-hi-puma-")) -} - -func TestAppPool_FindAppByDomainName_returnsAppWithBaseDomain(t *testing.T) { - t.Skip("temp") - appLinkDir := homedir.MustExpand("~/.puma-dev-test_app-test-base-subdomain-puma-dev") - testAppsToLink := map[string]string{ - "hipuma": "rack-hi-puma", - } - defer LinkTestApps(t, appLinkDir, testAppsToLink)() - - var events Events - - var testPool AppPool - testPool.Dir = appLinkDir - testPool.Events = &events - - app, err := testPool.FindAppByDomainName("foo.hipuma") - if err != nil { - assert.Fail(t, err.Error()) - } - - assert.True(t, strings.HasPrefix(app.Name, "rack-hi-puma-")) -}