From fa827ecb7facf980a0d54545932c220ab2b2ee80 Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Tue, 7 Feb 2023 17:08:59 +0100 Subject: [PATCH 1/3] Use arduino101load/version package to automatically change build version --- globals/globals.go | 13 +++++++++++++ go.mod | 5 +++++ go.sum | 2 ++ main.go | 7 +++---- version/version.go | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 globals/globals.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 version/version.go diff --git a/globals/globals.go b/globals/globals.go new file mode 100644 index 0000000..29f24a2 --- /dev/null +++ b/globals/globals.go @@ -0,0 +1,13 @@ +package globals + +import ( + "os" + "path/filepath" + + "github.com/arduino/arduino101load/version" +) + +var ( + // VersionInfo contains all info injected during build + VersionInfo = version.NewInfo(filepath.Base(os.Args[0])) +) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..3c70f4e --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/arduino/arduino101load + +go 1.19 + +require github.com/mattn/go-shellwords v1.0.12 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..da8b56c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= +github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= diff --git a/main.go b/main.go index fd951f6..7398d77 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "github.com/arduino/arduino101load/globals" shellwords "github.com/mattn/go-shellwords" ) @@ -34,8 +35,6 @@ var ( rtos_compliance_offset = flag.Int("rtos_fw_pos", 0, "RTOS FW ID offset") ) -const Version = "2.2.2" - const dfu_flags = "-d,8087:0ABA" const rtos_firmware = "quark.bin" const ble_firmware = "ble_core.bin" @@ -205,7 +204,7 @@ func main_load() { firmwarePath = filepath.Join(filepath.Dir(firmwarePath), "firmwares") if stat, err := os.Stat(*core); err == nil && stat.IsDir() { - firmwarePath = *core + firmwarePath = *core } else { firmwarePath = filepath.Join(firmwarePath, *core) } @@ -311,7 +310,7 @@ func main() { flag.Parse() - PrintlnVerbose(name + " " + Version + " - compiled with " + runtime.Version()) + PrintlnVerbose(globals.VersionInfo) if *copier { if *from == "" || *to == "" { diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..3f7261e --- /dev/null +++ b/version/version.go @@ -0,0 +1,39 @@ +package version + +import "fmt" + +var ( + defaultVersionString = "0.0.0-git" + versionString = "" + commit = "" + date = "" +) + +// Info is a struct that contains information about the application +type Info struct { + Application string `json:"Application"` + VersionString string `json:"VersionString"` + Commit string `json:"Commit"` + Date string `json:"Date"` +} + +// NewInfo returns a pointer to an updated Info struct +func NewInfo(application string) *Info { + return &Info{ + Application: application, + VersionString: versionString, + Commit: commit, + Date: date, + } +} + +func (i *Info) String() string { + return fmt.Sprintf("%[1]s Version: %[2]s Commit: %[3]s Date: %[4]s", i.Application, i.VersionString, i.Commit, i.Date) +} + +//nolint:gochecknoinits +func init() { + if versionString == "" { + versionString = defaultVersionString + } +} From 101fcd34b18af40679717d471a15b32009c47905 Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Tue, 7 Feb 2023 17:13:32 +0100 Subject: [PATCH 2/3] Add CI workflow to publish releases On every push of a tag named with a version format: - Build the project for all supported platforms. - Sign and notarize the macOS builds. - Create a GitHub release. - Builds and checksums are attached as release assets - A changelog generated from the commit history is added to the release description - If the tag has a pre-release version suffix, the GitHub release will be marked as a pre-release. - Upload the builds to Arduino's downloads server. --- .../release-go-crosscompile-task.yml | 119 +++++++++++++ DistTasks.yml | 158 ++++++++++++++++++ README.md | 1 + Taskfile.yml | 30 ++++ 4 files changed, 308 insertions(+) create mode 100644 .github/workflows/release-go-crosscompile-task.yml create mode 100644 DistTasks.yml create mode 100644 Taskfile.yml diff --git a/.github/workflows/release-go-crosscompile-task.yml b/.github/workflows/release-go-crosscompile-task.yml new file mode 100644 index 0000000..c119f22 --- /dev/null +++ b/.github/workflows/release-go-crosscompile-task.yml @@ -0,0 +1,119 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/release-go-crosscompile-task.md +name: Release + +env: + # As defined by the Taskfile's PROJECT_NAME variable + PROJECT_NAME: arduino101load + # As defined by the Taskfile's DIST_DIR variable + DIST_DIR: dist + # The project's folder on Arduino's download server for uploading builds + AWS_PLUGIN_TARGET: /arduino101load/ + ARTIFACT_NAME: dist + # See: https://github.com/actions/setup-go/tree/main#supported-version-syntax + GO_VERSION: "1.17" + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+*" + +jobs: + create-release-artifacts: + runs-on: ubuntu-latest + + strategy: + matrix: + os: + - Windows_32bit + - Windows_64bit + - Linux_32bit + - Linux_64bit + - Linux_ARMv6 + - Linux_ARMv7 + - Linux_ARM64 + - macOS_64bit + - macOS_ARM64 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Create changelog + # Avoid creating the same changelog for each os + if: matrix.os == 'Windows_32bit' + uses: arduino/create-changelog@v1 + with: + tag-regex: '^[0-9]+\.[0-9]+\.[0-9]+.*$' + filter-regex: '^\[(skip|changelog)[ ,-](skip|changelog)\].*' + case-insensitive-regex: true + changelog-file-path: "${{ env.DIST_DIR }}/CHANGELOG.md" + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Build + run: task dist:${{ matrix.os }} + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + if-no-files-found: error + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.DIST_DIR }} + + create-release: + runs-on: ubuntu-latest + needs: create-release-artifacts + + steps: + - name: Download artifact + uses: actions/download-artifact@v3 + with: + name: ${{ env.ARTIFACT_NAME }} + path: ${{ env.DIST_DIR }} + + - name: Create checksum file + working-directory: ${{ env.DIST_DIR}} + run: | + TAG="${GITHUB_REF/refs\/tags\//}" + sha256sum ${{ env.PROJECT_NAME }}_${TAG}* > ${TAG}-checksums.txt + + - name: Identify Prerelease + # This is a workaround while waiting for create-release action + # to implement auto pre-release based on tag + id: prerelease + run: | + wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.2.0.zip + unzip -p /tmp/3.2.0.zip semver-tool-3.2.0/src/semver >/tmp/semver && chmod +x /tmp/semver + if [[ "$(/tmp/semver get prerel "${GITHUB_REF/refs\/tags\//}")" ]]; then echo "IS_PRE=true" >> $GITHUB_OUTPUT; fi + + - name: Create Github Release and upload artifacts + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + bodyFile: ${{ env.DIST_DIR }}/CHANGELOG.md + draft: false + prerelease: ${{ steps.prerelease.outputs.IS_PRE }} + # NOTE: "Artifact is a directory" warnings are expected and don't indicate a problem + # (all the files we need are in the DIST_DIR root) + artifacts: ${{ env.DIST_DIR }}/* + + - name: Upload release files on Arduino downloads servers + uses: docker://plugins/s3 + env: + PLUGIN_SOURCE: "${{ env.DIST_DIR }}/*" + PLUGIN_TARGET: ${{ env.AWS_PLUGIN_TARGET }} + PLUGIN_STRIP_PREFIX: "${{ env.DIST_DIR }}/" + PLUGIN_BUCKET: ${{ secrets.DOWNLOADS_BUCKET }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/DistTasks.yml b/DistTasks.yml new file mode 100644 index 0000000..bb10fcb --- /dev/null +++ b/DistTasks.yml @@ -0,0 +1,158 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-crosscompile-task/DistTasks.yml +version: "3" + +# This taskfile is ideally meant to be project agnostic and could be dropped in +# on other Go projects with minimal or no changes. +# +# To use it simply add the following lines to your main taskfile: +# includes: +# dist: ./DistTasks.yml +# +# The following variables must be declared in the including taskfile for the +# build process to work correctly: +# * DIST_DIR: the folder that will contain the final binaries and packages +# * PROJECT_NAME: the name of the project, used in package name +# * VERSION: the version of the project, used in package name and checksum file +# * LD_FLAGS: flags used at build time +# +# The project MUST contain a LICENSE.txt file in the root folder or packaging will fail. + +tasks: + Windows_32bit: + desc: Builds Windows 32 bit binaries + env: + GOOS: "windows" + GOARCH: "386" + GO386: "softfloat" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}}.exe {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + zip {{.PACKAGE_NAME}} bin/{{.PROJECT_NAME}}.exe bin/firmwares + vars: + PACKAGE_PLATFORM: "Windows_32bit" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip" + + Windows_64bit: + desc: Builds Windows 64 bit binaries + env: + GOOS: "windows" + GOARCH: "amd64" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}}.exe {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + zip {{.PACKAGE_NAME}} bin/{{.PROJECT_NAME}}.exe bin/firmwares + vars: + PACKAGE_PLATFORM: "Windows_64bit" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.zip" + + Linux_32bit: + desc: Builds Linux 32 bit binaries + env: + GOOS: "linux" + GOARCH: "386" + GO386: "softfloat" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "Linux_32bit" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + Linux_64bit: + desc: Builds Linux 64 bit binaries + env: + GOOS: "linux" + GOARCH: "amd64" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "Linux_64bit" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + Linux_ARMv7: + desc: Builds Linux ARMv7 binaries + env: + GOOS: "linux" + GOARCH: "arm" + GOARM: 7 + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "Linux_ARMv7" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + Linux_ARMv6: + desc: Builds Linux ARMv6 binaries + env: + GOOS: "linux" + GOARCH: "arm" + GOARM: 6 + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "Linux_ARMv6" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + Linux_ARM64: + desc: Builds Linux ARM64 binaries + env: + GOOS: "linux" + GOARCH: "arm64" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "Linux_ARM64" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + macOS_64bit: + desc: Builds Mac OS X 64 bit binaries + env: + GOOS: "darwin" + GOARCH: "amd64" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "macOS_64bit" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" + + macOS_ARM64: + desc: Builds Mac OS X ARM64 binaries + env: + GOOS: "darwin" + GOARCH: "arm64" + cmds: + - | + go build -o {{.DIST_DIR}}/bin/{{.PROJECT_NAME}} {{.LDFLAGS}} + cd {{.DIST_DIR}} + cp -R ../firmwares bin/ + tar cz bin/ -f {{.PACKAGE_NAME}} + vars: + PACKAGE_PLATFORM: "macOS_ARM64" + PACKAGE_NAME: "{{.PROJECT_NAME}}_{{.VERSION}}_{{.PACKAGE_PLATFORM}}.tar.gz" diff --git a/README.md b/README.md index 246e950..1d981c8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # arduino101load +[![Release status](https://github.com/arduino/arduino101load/actions/workflows/release-go-crosscompile-task.yml/badge.svg)](https://github.com/arduino/arduino101load/actions/workflows/release-go-crosscompile-task.yml) multiplatform launcher for Arduino101 dfu-util flashing utility ## Compiling diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..7f6ff18 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,30 @@ +# See: https://taskfile.dev/#/usage +version: "3" + +includes: + dist: ./DistTasks.yml + +vars: + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/release-go-task/Taskfile.yml + PROJECT_NAME: arduino101load + DIST_DIR: "dist" + # build vars + COMMIT: + sh: echo "$(git log --no-show-signature -n 1 --format=%h)" + TIMESTAMP: + sh: echo "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" + TIMESTAMP_SHORT: + sh: echo "{{now | date "20060102"}}" + TAG: + sh: echo "$(git tag --points-at=HEAD 2> /dev/null | head -n1)" + VERSION: "{{if .NIGHTLY}}nightly-{{.TIMESTAMP_SHORT}}{{else if .TAG}}{{.TAG}}{{else}}{{.PACKAGE_NAME_PREFIX}}git-snapshot{{end}}" + CONFIGURATION_PACKAGE: "github.com/arduino/arduino101load/version" + LDFLAGS: >- + -ldflags + ' + -X {{.CONFIGURATION_PACKAGE}}.versionString={{.VERSION}} + -X {{.CONFIGURATION_PACKAGE}}.commit={{.COMMIT}} + -X {{.CONFIGURATION_PACKAGE}}.date={{.TIMESTAMP}} + ' + +tasks: {} From 09bc5d156d6f642c847da09e79fcf3e6cb7cdf50 Mon Sep 17 00:00:00 2001 From: Matteo Pologruto Date: Tue, 7 Feb 2023 17:34:02 +0100 Subject: [PATCH 3/3] Remove old release script --- deploy.sh | 43 ------------------------------------------ package_index.template | 41 ---------------------------------------- 2 files changed, 84 deletions(-) delete mode 100755 deploy.sh delete mode 100644 package_index.template diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 3bbf960..0000000 --- a/deploy.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -xe - -VERSION=`cat main.go| grep "const Version" |cut -f4 -d " " | tr -d '"'` - -#Remember to set GOROOT accordingly with your installation - -export GOPATH=$PWD - -declare -a target_folders=("linux_amd64" "linux_386" "linux_arm" "darwin_amd64" "windows_386") - -rm -rf distrib -mkdir distrib - -package_index=`cat package_index.template | sed s/%%VERSION%%/${VERSION}/` - -for folder in "${target_folders[@]}" -do - rm -rf arduino101load* - rm -rf bin - mkdir bin - IFS=_ read -a fields <<< $folder - GOOS=${fields[0]} GOARCH=${fields[1]} go build - FILENAME=arduino101load-${VERSION}-${folder}.tar.bz2 - cp -r arduino101load* firmwares/ bin - tar cjvf ${FILENAME} bin/ - T_OS=`echo ${folder} | awk '{print toupper($0)}'` - SHASUM=`sha256sum ${FILENAME} | cut -f1 -d" "` - SIZE=`stat --printf="%s" ${FILENAME}` - package_index=`echo $package_index | - sed s/%%FILENAME_${T_OS}%%/${FILENAME}/ | - sed s/%%FILENAME_${T_OS}%%/${FILENAME}/ | - sed s/%%SIZE_${T_OS}%%/${SIZE}/ | - sed s/%%SHA_${T_OS}%%/${SHASUM}/` - - mv ${FILENAME} distrib/ -done - -set +x - -echo ================== CUT ME HERE ===================== - -echo ${package_index} | python -m json.tool - diff --git a/package_index.template b/package_index.template deleted file mode 100644 index 9badc5e..0000000 --- a/package_index.template +++ /dev/null @@ -1,41 +0,0 @@ - { - "name": "arduino101load", - "version": "%%VERSION%%", - "systems": [ - { - "host": "i386-apple-darwin11", - "url": "http://downloads.arduino.cc/tools/%%FILENAME_DARWIN_AMD64%%", - "archiveFileName": "%%FILENAME_DARWIN_AMD64%%", - "size": "%%SIZE_DARWIN_AMD64%%", - "checksum": "SHA-256:%%SHA_DARWIN_AMD64%%" - }, - { - "host": "arm-linux-gnueabihf", - "url": "http://downloads.arduino.cc/tools/%%FILENAME_LINUX_ARM%%", - "archiveFileName": "%%FILENAME_LINUX_ARM%%", - "size": "%%SIZE_LINUX_ARM%%", - "checksum": "SHA-256:%%SHA_LINUX_ARM%%" - }, - { - "host": "x86_64-linux-gnu", - "url": "http://downloads.arduino.cc/tools/%%FILENAME_LINUX_AMD64%%", - "archiveFileName": "%%FILENAME_LINUX_AMD64%%", - "size": "%%SIZE_LINUX_AMD64%%", - "checksum": "SHA-256:%%SHA_LINUX_AMD64%%" - }, - { - "host": "i686-linux-gnu", - "url": "http://downloads.arduino.cc/tools/%%FILENAME_LINUX_386%%", - "archiveFileName": "%%FILENAME_LINUX_386%%", - "size": "%%SIZE_LINUX_386%%", - "checksum": "SHA-256:%%SHA_LINUX_386%%" - }, - { - "host": "i686-mingw32", - "url": "http://downloads.arduino.cc/tools/%%FILENAME_WINDOWS_386%%", - "archiveFileName": "%%FILENAME_WINDOWS_386%%", - "size": "%%SIZE_WINDOWS_386%%", - "checksum": "SHA-256:%%SHA_WINDOWS_386%%" - } - ] - }