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:
|
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
|
|
||||||
|
|
@ -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'
|
||||||
|
|
|
||||||
46
index.js
46
index.js
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loadingā¦
Reference in a new issue