Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Build
description: Build release binaries

runs:
using: "composite"
steps:
- name: Build release binaries
shell: bash
run: |
mage -v build:release
mage -v release:prep
find bin -type f -printf "%p %k KB\n"
find dist -type f -printf "%p %k KB\n"
37 changes: 37 additions & 0 deletions .github/actions/release-ftp/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Upload Release to FTP"
description: "Uploads all release ZIPs to an FTP server"

inputs:
ftp_host:
description: "FTP server hostname or IP address"
required: true
ftp_username:
description: "FTP username"
required: true
ftp_password:
description: "FTP password"
required: true
ftp_path:
description: "FTP remote directory path"
required: true
local_path:
description: "Local directory path containing release binaries"
required: true
release_version:
description: "Version number for release. For example: 1.2.123"
required: true

runs:
using: "composite"
steps:
- name: Upload release ZIPs to FTP server
shell: bash
run: |
mage -v release:ftp
env:
FTP_HOST: ${{ inputs.ftp_host }}
FTP_USERNAME: ${{ inputs.ftp_username }}
FTP_PASSWORD: ${{ inputs.ftp_password }}
FTP_PATH: ${{ inputs.ftp_path }}
LOCAL_PATH: ${{ inputs.local_path }}
RELEASE_VERSION: ${{ inputs.release_version }}
8 changes: 1 addition & 7 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
name: Test
description: Run Go tests
description: Run tests

runs:
using: "composite"
steps:
- name: Run Tests
shell: bash
run: mage -v test

- name: Run Build
shell: bash
run: |
mage -v build:release
ls -la bin
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
test:
runs-on: ubuntu-latest
name: Run Tests

steps:
- uses: actions/checkout@v6
- name: Go Setup
uses: ./.github/actions/go-setup

- name: Run Tests
uses: ./.github/actions/test

release:
needs: test
runs-on: ubuntu-latest
name: Build release binaries

steps:
- uses: actions/checkout@v6
- name: Go Setup
uses: ./.github/actions/go-setup

- name: Build release binaries
uses: ./.github/actions/build

- name: Release to GitHub via tagged-release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
name: v${{ github.ref_name }}
draft: true
prerelease: false
files: |
./dist/reactenv_${{ github.ref_name }}_darwin_amd64.zip
./dist/reactenv_${{ github.ref_name }}_darwin_arm64.zip
./dist/reactenv_${{ github.ref_name }}_freebsd_amd64.zip
./dist/reactenv_${{ github.ref_name }}_freebsd_arm.zip
./dist/reactenv_${{ github.ref_name }}_linux_amd64.zip
./dist/reactenv_${{ github.ref_name }}_linux_arm64.zip
./dist/reactenv_${{ github.ref_name }}_netbsd_amd64.zip
./dist/reactenv_${{ github.ref_name }}_netbsd_arm.zip
./dist/reactenv_${{ github.ref_name }}_openbsd_amd64.zip
./dist/reactenv_${{ github.ref_name }}_windows_amd64.zip

- name: Release to FTP
uses: ./.github/actions/release-ftp
with:
ftp_host: ${{ secrets.FTP_HOST }}
ftp_username: ${{ secrets.FTP_USERNAME }}
ftp_password: ${{ secrets.FTP_PASSWORD }}
ftp_path: ${{ secrets.FTP_PATH }}
local_path: ./dist
release_version: ${{ github.ref_name }}
3 changes: 3 additions & 0 deletions .github/workflows/test-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ jobs:

- name: Run Tests
uses: ./.github/actions/test

- name: Build release binaries
uses: ./.github/actions/build
3 changes: 3 additions & 0 deletions .github/workflows/test-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:

- name: Send coverage
uses: ./.github/actions/coverage

- name: Build release binaries
uses: ./.github/actions/build
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
.yarn/
.idea/
.vagrant/
bin/**/*
bin/
dist/
target/
node_modules/

Expand All @@ -12,6 +13,8 @@ node_modules/
*.tar
*.tar.gz

cover.out

!npm/reactenv/bin/reactenv
npm/reactenv-darwin-arm64/reactenv
npm/reactenv-darwin-x64/reactenv
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-version v1.8.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/iochan v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pkg/sftp v1.13.10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down Expand Up @@ -84,6 +86,8 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/pkg/sftp v1.13.10 h1:+5FbKNTe5Z9aspU88DPIKJ9z2KZoaGCu6Sr6kKR/5mU=
github.com/pkg/sftp v1.13.10/go.mod h1:bJ1a7uDhrX/4OII+agvy28lzRvQrmIQuaHrcI1HbeGA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down
87 changes: 84 additions & 3 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

type Build mg.Namespace
type Release mg.Namespace
type Npm mg.Namespace

var Aliases = map[string]interface{}{
Expand Down Expand Up @@ -78,12 +79,18 @@ func Bench() error {
func (Build) Clean() error {
log := NewLogger()
defer log.End()
log.Info("cleaning bin directory")
log.Info("cleaning bin and dist directories")

if err := os.RemoveAll("bin"); err != nil {
return log.Error(err)
}

if err := os.RemoveAll("dist"); err != nil {
return log.Error(err)
}

log.Info("cleaning npm directories")

return fs.WalkDir(os.DirFS("npm"), ".", func(filePath string, d fs.DirEntry, err error) error {
if d.IsDir() ||
filePath == "reactenv/bin/reactenv" ||
Expand All @@ -105,7 +112,7 @@ func (Build) Debug() error {
}

func (Build) Release() error {
mg.Deps(Build.Clean, BumpVersion)
mg.Deps(Build.Clean)

log := NewLogger()
defer log.End()
Expand All @@ -130,7 +137,12 @@ func (Build) Release() error {
// Release
// ----------------------------------------------------------------------------

func Release() error {
// Prep for release
//
// - Copy each binary to `npm` directories
//
// - Zip up binaries, then copy zips to `dist` directory
func (Release) Prep() error {
log := NewLogger()
defer log.End()

Expand Down Expand Up @@ -211,6 +223,75 @@ func Release() error {
}
}

// Copy zips to dist directory
log.Debug("copying release zips to dist directory")
if err := os.MkdirAll("dist", 0755); err != nil {
return log.Error("failed to create dist directory:", err)
}
for _, arch := range releaseArchs {
zipFilePath := fmt.Sprintf("bin/%s_%s_%s.zip", BINARY_FILENAME, releaseVersion, arch)
CopyFile(zipFilePath, path.Join("dist", path.Base(zipFilePath)))
}

return nil
}

// Upload all files in a directory to an FTP server (configurable). Used to upload
// all release zips in `dist`.
//
// A new directory is created on the FTP server for the release version,
// and the release files (everything in `LOCAL_PATH` directory) are uploaded to it.
func (Release) FTP() error {
log := NewLogger()
defer log.End()

ftpHost := os.Getenv("FTP_HOST")
ftpUsername := os.Getenv("FTP_USERNAME")
ftpPassword := os.Getenv("FTP_PASSWORD")
ftpPath := os.Getenv("FTP_PATH")
localPath := os.Getenv("LOCAL_PATH")
releaseVersion := os.Getenv("RELEASE_VERSION")
ftpReleasePath := path.Join(ftpPath, releaseVersion)

log.Info("ftp upload path: ", ftpReleasePath)

if ftpHost == "" || ftpUsername == "" || ftpPassword == "" || ftpPath == "" || localPath == "" || releaseVersion == "" {
return log.Error("required FTP environment variables not set")
}

err := FTPUploadDir(ftpHost, ftpUsername, ftpPassword, ftpReleasePath, localPath, releaseVersion)
if err != nil {
return log.Error("failed to upload release files to FTP server:", err)
}

return nil
}

// Runs `npm publish` for each npm package.
func (Release) NPM() error {
log := NewLogger()
defer log.End()

// Read all npm directories
npmDirectories, err := fs.ReadDir(os.DirFS("npm"), ".")
if err != nil {
return log.Error("failed to read npm directories:", err)
}

// Run `npm publish` for each npm package
for _, dir := range npmDirectories {
if !dir.IsDir() || !strings.HasPrefix(dir.Name(), "reactenv") {
continue
}

packagePath := path.Join("npm", dir.Name())
log.Info("publishing npm package: ", packagePath)

if err := RunStream([]string{"npm", "publish"}, packagePath, false); err != nil {
return log.Error("failed to publish npm package:", packagePath, err)
}
}

return nil
}

Expand Down
Loading