Skip to content

Commit

Permalink
feat: output workflow url with test metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta authored Aug 21, 2023
2 parents 6214629 + 6c7ffe3 commit 2a8b181
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ runs:
SUBDOMAIN: ${{ inputs.subdomain-url }}
JSON: ${{ inputs.json }}
SPECS: ${{ inputs.specs }}
JOB_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
repository: ${{ steps.github.outputs.action_repository }}
ref: ${{ steps.github.outputs.action_sha || steps.github.outputs.action_ref }}
dockerfile: Dockerfile
opts: --network=host
args: test --url="$URL" --json="$JSON" --specs="$SPECS" --subdomain-url="$SUBDOMAIN" -- ${{ inputs.args }}
args: test --url="$URL" --json="$JSON" --specs="$SPECS" --subdomain-url="$SUBDOMAIN" --job-url="$JOB_URL" -- ${{ inputs.args }}
build-args: |
VERSION:${{ steps.github.outputs.action_ref }}
- name: Create the XML
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-prod-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
path_to_add: 'fixtures.car'
- name: Wait for pinning
run: |
sleep 180 # 3 minutes
sleep 20 # 20 seconds
# see rational in https://github.com/ipfs/gateway-conformance/pull/108#discussion_r1274628865
test:
runs-on: "ubuntu-latest"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `--version` flag shows the current version
- Metadata logging used to associate tests with custom data like versions, specs identifiers, etc.
- Output Github's workflow URL with metadata. [PR](https://github.com/ipfs/gateway-conformance/pull/145)

## [0.3.0] - 2023-07-31
### Added
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ fixtures.car: gateway-conformance
./gateway-conformance extract-fixtures --merged=true --dir=.

gateway-conformance:
go build -ldflags="-X github.com/ipfs/gateway-conformance/tooling.Version=$(CLI_VERSION)" -o ./gateway-conformance ./cmd/gateway-conformance
go build \
-ldflags="-X github.com/ipfs/gateway-conformance/tooling.Version=$(CLI_VERSION)" \
-o ./gateway-conformance \
./cmd/gateway-conformance

test-docker: docker fixtures.car gateway-conformance
./gc test
Expand Down
8 changes: 7 additions & 1 deletion aggregate-into-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ inputs.forEach((input, index) => {
// extract TestMetadata & version
const metadata = input[TestMetadata]["meta"];
const version = metadata['version'];
const jobURL = metadata['job_url'];

const col = [name, version];
let versionCell = version
if (jobURL) {
versionCell = `[${version}](${jobURL})`;
}

const col = [name, versionCell];

// extract results
keys.forEach((key) => {
Expand Down
10 changes: 9 additions & 1 deletion cmd/gateway-conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func main() {
var gatewayURL string
var subdomainGatewayURL string
var jsonOutput string
var jobURL string
var specs string
var directory string
var merged bool
Expand Down Expand Up @@ -107,6 +108,13 @@ func main() {
Value: "",
Destination: &jsonOutput,
},
&cli.StringFlag{
Name: "job-url",
Aliases: []string{},
Usage: "The Job URL where this run will be visible.",
Value: "",
Destination: &jobURL,
},
&cli.StringFlag{
Name: "specs",
Usage: "Accepts a spec (test only this spec), a +spec (test also this immature spec), or a -spec (do not test this mature spec).",
Expand All @@ -127,7 +135,7 @@ func main() {
args = append(args, fmt.Sprintf("-specs=%s", specs))
}

ldFlag := fmt.Sprintf("-ldflags=-X github.com/ipfs/gateway-conformance/tooling.Version=%s", tooling.Version)
ldFlag := fmt.Sprintf("-ldflags=-X github.com/ipfs/gateway-conformance/tooling.Version=%s -X github.com/ipfs/gateway-conformance/tooling.JobURL=%s", tooling.Version, jobURL)
args = append(args, ldFlag)

args = append(args, cCtx.Args().Slice()...)
Expand Down
1 change: 1 addition & 0 deletions tests/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import (

func TestMetadata(t *testing.T) {
tooling.LogVersion(t)
tooling.LogJobURL(t)
}
1 change: 1 addition & 0 deletions tooling/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

var (
Version = "dev"
JobURL = ""
)

func Home() string {
Expand Down
10 changes: 10 additions & 0 deletions tooling/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

func LogMetadata(t *testing.T, value interface{}) {
t.Helper()

jsonValue, err := json.Marshal(value)
if err != nil {
t.Errorf("Failed to encode value: %v", err)
Expand All @@ -21,3 +23,11 @@ func LogVersion(t *testing.T) {
Version: Version,
})
}

func LogJobURL(t *testing.T) {
LogMetadata(t, struct {
JobURL string `json:"job_url"`
}{
JobURL: JobURL,
})
}

0 comments on commit 2a8b181

Please sign in to comment.