Compare commits

...

3 commits
v2.1.0 ... main

Author SHA1 Message Date
Erik Burton
8b4478c701 Updating to node20 2023-10-18 09:05:29 +02:00
Y. Meyer-Norwood
ed11bda1c4
Fix installation on Windows runners (#10)
* Correctly identify windows os

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Prevent darwin from being reported as Linux

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove unix specific logging and determine .zip extension on windows

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add selftest on windows

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Run self test on all push events (for testing)

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Inline postfix declaration

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Separate extension detection from postfix

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Correctly avoid assignment to const variable

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Make postfix constant

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Prevent curl from assuming tar.gz format

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Refactor download stage

* Separate logical steps
* Use string interpolation for curl command

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use environment defined temp path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix missing `$`

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Correct all references to hardcoded filename

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Attempt debugging missing download

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Restore original console loggers

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* USe GOOs

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Extract binary directly to GOPATH rather than hardcoded lib path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Properly log GOOS detection

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove GOOS detection as GOOS not in environment

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Replace GOPATH with system dependent lib path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix windows path separator problems

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Simplify archive path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix escape character

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use more meaningful name for binpath

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix whitespace

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add debugger lines

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add debugger lines for executed commands

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use console debug instead of log

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use program files as binpath

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add install directory to path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove debuggers

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix os check

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove redundant pathsep variable

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add documentation comments

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix missing path separators

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Explicitly echo bin path into GITHUB_PATH

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Quote bin path when `cd`ing into it to avoid shell globbing

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Ensure bin path exists

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Attempt to prevent existing directories causing problems

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use core.addPath to add binpath to job's PATH

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Attempt to use pre-existing lib path instead of creating new one

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add debugger for PATH variable

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List System32 files to look for gotestfmt binary

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove debugger

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Manually setup binpath and add it to system path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List PATH targets for debugging

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add debuggers for userprofile

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List install target's contents

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List files recursively and verbosely

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Search `/bin` specifically

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Only manually add the binpath on windows

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List all PATHs

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Split on correct separator

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Don't force the directory to exist/into PATH

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Attempt to create custom binpath in windows

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix mkdir invocation

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Create all path components

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List all files in target directory

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Try using pwsh for Windows runner

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Try using exe for pwsh

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove testing step

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List files extracted to bin path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Expand debugger

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List files in temporary directory

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List files in current directory

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Rather than changing directories, specify target to tar command

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Quote parameters to tar command

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Specify target directory before target files

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Move extracted binary manually

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Add callback to file move

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use system defined target file

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Correct interpolation

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Copy binfile instead of renaming to prevent cross-device linking

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List installed files

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Use binfile in final success log message

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove explicit path separator

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Specify fs.constants.COPYFILE_EXCL copy mode

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Extract archive directly into workspace

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove redundant `binfile` variable

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove debugger

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* List all files in workspace

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove debugging steps

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove inline comments

This is per @engelmi's comment: https://github.com/GoTestTools/gotestfmt-action/pull/10/files#r1017614705

Signed-off-by: Y. Meyer-Norwood <106889957+norwd@users.noreply.github.com>

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>
Signed-off-by: Y. Meyer-Norwood <106889957+norwd@users.noreply.github.com>
2022-11-10 17:43:54 +01:00
Yuri Norwood
19aa3d4945
Extend selftest workflow to multiple runners (#9)
* Extend selftest workflow to multiple runners

This should help catch errors like #4 and #8 by ensuring that gotestfmt can run on all the major OS runners for GitHub Actions.

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Separate windows step from *nix runners

This allows `bash` and `pwsh` syntax to be used separately to avoid having to write the test as a polyglot 😬

Also added `secrets.GITHUB_TOKEN` as a fallback in case the repo secret `secrets.GH_TOKEN` is not set up, e.g. in a fork.

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Remove `/tmp` directory for artifacts

On MacOS, this results in:

```
Error: Provided rootDirectory /tmp is not a valid directory
```

On Windows this results in:

```
Error: No files were found with the provided path: /tmp/gotest.windows.log. No artifacts will be uploaded.
```

Both seem to be unhappy with `/tmp`, since the workspace is implicitly cleaned up at the end of the workflow, there shouldn't be a need to specify `/tmp`.

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Name each workflow run of the matrix

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Fix artifact path

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Simplify workflow by just using bash universally

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

* Apply suggestions from code review

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>

Signed-off-by: Yuri Norwood <106889957+norwd@users.noreply.github.com>
2022-11-04 10:00:11 +01:00
3 changed files with 51 additions and 49 deletions

View file

@ -1,52 +1,42 @@
on: on:
pull_request: pull_request:
name: Self-test name: Self-test
jobs: jobs:
self-test-ubuntu:
name: on Ubuntu self-test:
runs-on: ubuntu-latest strategy:
fail-fast: false
matrix:
os: ['ubuntu', 'macos', 'windows']
name: on ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
steps: steps:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v2 uses: actions/setup-go@v2
with: with:
go-version: 1.16 go-version: 1.16
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Install gotestfmt - name: Install gotestfmt
uses: ./ uses: ./
with: with:
token: ${{ secrets.GH_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Run gotestfmt - name: Run gotestfmt
working-directory: testdata working-directory: testdata
run: go test -json -v ./... 2>&1 | tee /tmp/gotest.log | gotestfmt shell: bash
run: |
go test -json -v ./... 2>&1 | tee gotest.${{ matrix.os }}.log | gotestfmt
- name: Upload test log - name: Upload test log
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
if: always() if: always()
with: with:
name: test-log-ubuntu name: test-log-${{ matrix.os }}
path: /tmp/gotest.log path: testdata/gotest.${{ matrix.os }}.log
if-no-files-found: error if-no-files-found: error
self-test-macos:
name: on MacOS
runs-on: macos-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Checkout
uses: actions/checkout@v2
- name: Install gotestfmt
uses: ./
with:
token: ${{ secrets.GH_TOKEN }}
- name: Run gotestfmt
working-directory: testdata
run: go test -json -v ./... 2>&1 | tee ./gotest.log | gotestfmt
- name: Upload test log
uses: actions/upload-artifact@v3
if: always()
with:
name: test-log-macos
path: ./testdata/gotest.log
if-no-files-found: error

View file

@ -21,5 +21,5 @@ inputs:
required: false required: false
default: 'gotestfmt' default: 'gotestfmt'
runs: runs:
using: 'node16' using: 'node20'
main: 'index.js' main: 'index.js'

View file

@ -4,36 +4,40 @@ const fs = require("fs")
const { execSync } = require("child_process") const { execSync } = require("child_process")
async function downloadRelease(octokit, os, org, repo, release, token) { async function downloadRelease(octokit, os, org, repo, release, token) {
const postfix = `_${os}_amd64.${os === "windows" ? "zip" : "tar.gz"}`;
const tempdir = os === "windows" ? process.env.TEMP + "\\" : "/tmp/";
const extract = os === "windows" ? "tar -xvf" : "tar -xvzf";
const archive = `${tempdir}gotestfmt${postfix}`;
const releaseAssets = await octokit.rest.repos.listReleaseAssets({ const releaseAssets = await octokit.rest.repos.listReleaseAssets({
owner: org, owner: org,
repo: repo, repo: repo,
release_id: release.id, release_id: release.id,
}) })
tarPostfix = `_${os}_amd64.tar.gz`
for (let asset of releaseAssets.data) { for (let asset of releaseAssets.data) {
console.log("Examining release asset " + asset.name + " at " + asset.browser_download_url + " ...") console.log("Examining release asset " + asset.name + " at " + asset.browser_download_url + " ...")
if (asset.name.endsWith(tarPostfix)) { if (asset.name.endsWith(postfix)) {
console.log("Found Linux binary named " + asset.name + " at " + asset.browser_download_url + " , attempting download...") console.log("Found binary named " + asset.name + " at " + asset.browser_download_url + " , attempting download...")
if (token) { if (token) {
execSync("curl -L -o /tmp/gotestfmt.tar.gz -H \"Authorization: Bearer " + token + "\" " + asset.browser_download_url) execSync(`curl -L -o ${archive} -H "Authorization: Bearer ${token}" ${asset.browser_download_url}`)
} else { } else {
execSync("curl -L -o /tmp/gotestfmt.tar.gz " + asset.browser_download_url) execSync(`curl -L -o ${archive} ${asset.browser_download_url}`)
} }
console.log("Creating /usr/local/lib/gotestfmt directory...")
execSync("sudo mkdir -p /usr/local/lib/gotestfmt") console.log("Unpacking archive file...")
console.log("Unpacking tar file...") core.addPath(process.env.GITHUB_WORKSPACE)
execSync("cd /usr/local/lib/gotestfmt && sudo tar -xvzf /tmp/gotestfmt.tar.gz") process.chdir(process.env.GITHUB_WORKSPACE)
console.log("Removing tarball...") execSync(`${extract} "${archive}"`)
fs.unlinkSync("/tmp/gotestfmt.tar.gz")
console.log("Creating /usr/local/bin directory if it does not exist already...") console.log("Removing asset archive...")
execSync("sudo mkdir -p /usr/local/bin") fs.unlinkSync(archive)
console.log("Linking gotestfmt...")
execSync("sudo ln -s /usr/local/lib/gotestfmt/gotestfmt /usr/local/bin/gotestfmt")
console.log("Successfully set up gotestfmt.") console.log("Successfully set up gotestfmt.")
return return
} }
} }
throw `No release asset matched postfix '${tarPostfix}'.`
throw `No release asset matched postfix '${postfix}'.`
} }
async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, token) { async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, token) {
@ -73,8 +77,16 @@ async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, tok
} }
async function determineOS() { async function determineOS() {
const os = execSync("uname").toString().trim().toLowerCase() const uname = execSync("uname")
let os = uname.toString().trim().toLowerCase()
if (os.indexOf("msys_nt") === 0)
{
os = "windows";
}
console.log(`Running on OS '${os}'`) console.log(`Running on OS '${os}'`)
return os return os
} }