mirror of
https://github.com/GoTestTools/gotestfmt-action.git
synced 2026-02-08 08:47:28 +00:00
Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b4478c701 | ||
|
|
ed11bda1c4 | ||
|
|
19aa3d4945 |
3 changed files with 51 additions and 49 deletions
52
.github/workflows/selftest.yml
vendored
52
.github/workflows/selftest.yml
vendored
|
|
@ -1,52 +1,42 @@
|
|||
on:
|
||||
pull_request:
|
||||
|
||||
name: Self-test
|
||||
jobs:
|
||||
self-test-ubuntu:
|
||||
name: on Ubuntu
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
self-test:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: ['ubuntu', 'macos', 'windows']
|
||||
|
||||
name: on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}-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 }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Run gotestfmt
|
||||
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
|
||||
uses: actions/upload-artifact@v3
|
||||
if: always()
|
||||
with:
|
||||
name: test-log-ubuntu
|
||||
path: /tmp/gotest.log
|
||||
name: test-log-${{ matrix.os }}
|
||||
path: testdata/gotest.${{ matrix.os }}.log
|
||||
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
|
||||
|
|
@ -21,5 +21,5 @@ inputs:
|
|||
required: false
|
||||
default: 'gotestfmt'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'index.js'
|
||||
|
|
|
|||
46
index.js
46
index.js
|
|
@ -4,36 +4,40 @@ const fs = require("fs")
|
|||
const { execSync } = require("child_process")
|
||||
|
||||
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({
|
||||
owner: org,
|
||||
repo: repo,
|
||||
release_id: release.id,
|
||||
})
|
||||
tarPostfix = `_${os}_amd64.tar.gz`
|
||||
|
||||
for (let asset of releaseAssets.data) {
|
||||
console.log("Examining release asset " + asset.name + " at " + asset.browser_download_url + " ...")
|
||||
if (asset.name.endsWith(tarPostfix)) {
|
||||
console.log("Found Linux binary named " + asset.name + " at " + asset.browser_download_url + " , attempting download...")
|
||||
if (asset.name.endsWith(postfix)) {
|
||||
console.log("Found binary named " + asset.name + " at " + asset.browser_download_url + " , attempting download...")
|
||||
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 {
|
||||
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 tar file...")
|
||||
execSync("cd /usr/local/lib/gotestfmt && sudo tar -xvzf /tmp/gotestfmt.tar.gz")
|
||||
console.log("Removing tarball...")
|
||||
fs.unlinkSync("/tmp/gotestfmt.tar.gz")
|
||||
console.log("Creating /usr/local/bin directory if it does not exist already...")
|
||||
execSync("sudo mkdir -p /usr/local/bin")
|
||||
console.log("Linking gotestfmt...")
|
||||
execSync("sudo ln -s /usr/local/lib/gotestfmt/gotestfmt /usr/local/bin/gotestfmt")
|
||||
|
||||
console.log("Unpacking archive file...")
|
||||
core.addPath(process.env.GITHUB_WORKSPACE)
|
||||
process.chdir(process.env.GITHUB_WORKSPACE)
|
||||
execSync(`${extract} "${archive}"`)
|
||||
|
||||
console.log("Removing asset archive...")
|
||||
fs.unlinkSync(archive)
|
||||
|
||||
console.log("Successfully set up gotestfmt.")
|
||||
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) {
|
||||
|
|
@ -73,8 +77,16 @@ async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, tok
|
|||
}
|
||||
|
||||
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}'`)
|
||||
|
||||
return os
|
||||
}
|
||||
|
||||
|
|
|
|||
Loadingā¦
Reference in a new issue