Skip to content

Commit

Permalink
[Integration tests]: manually get the current commit for the action w…
Browse files Browse the repository at this point in the history
…hen bootstrapping the project. (#405)

This PR does two things:
* Moves testing to a reusable workflow which is now shared between the
`main`, `pr`, and `release` workflows.
* Updates the integration tests to use the version of the
grafana-app-sdk that matches the code the action is being run against
(using a `replace` directive in the `go.mod`, as using `GITHUB_SHA`
doesn't cooperate with `go get` in PR builds).

Currently, the branch protection settings for `main` require that an
action named `test` complete successfully to merge (which no longer
exists the same way, so this blocks indefinitely), once this PR is
approved I will update the branch protection settings to require `test /
unit-test`, `test / integration-test`, and `test / build` instead, then
merge this PR so other PR's will need to merge in from main to get
correct testing.
  • Loading branch information
IfSentient authored Sep 18, 2024
1 parent 783cd4d commit 73db82e
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 395 deletions.
138 changes: 1 addition & 137 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,140 +7,4 @@ on:

jobs:
test:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# make test
- name: Test
run: go test -v ./...
build:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
# Go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# Preflight checks
- name: Preflight checks
run: make check-go-version
# make build
- name: Build
run: go build -v cmd/grafana-app-sdk/*.go
integration-test:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: 'grafana-app-sdk'
# Go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: './grafana-app-sdk/go.mod'
# Install the CLI
- name: Install the CLI
run: cd cmd/grafana-app-sdk && go install && cd -
working-directory: ./grafana-app-sdk
# Generate code
- name: Copy test CUE files & data
run: |
mkdir -p codegen-tests && cd codegen-tests
grafana-app-sdk project init "codegen-tests"
cp ../grafana-app-sdk/codegen/cuekind/testing/*.cue kinds/
mkdir -p cmp && cp -R ../grafana-app-sdk/codegen/testing/golden_generated/* cmp/
find ./cmp -iname '*.txt' -exec bash -c 'mv -- "$1" "${1%.txt}"' bash {} \;
- name: Generate code
run: |
cd codegen-tests
grafana-app-sdk generate --kindgrouping=kind --gogenpath=pkg/gen1 --tsgenpath=ts/gen1 --crdencoding=json --nomanifest
grafana-app-sdk generate --kindgrouping=group --gogenpath=pkg/gen2 --tsgenpath=ts/gen2 --crdencoding=yaml --nomanifest
diff pkg/gen1/resource/customkind cmp/go/groupbykind/customkind > diff.txt
sed -i '/^Common subdirectories/d' diff.txt
difflines=$(wc -l diff.txt | awk '{ print $1 }')
echo "GoGroupByKindDiff=${difflines}" >> $GITHUB_ENV
- name: Compare generated code
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let diff = '';
const options = {
outStream: fs.createWriteStream('/dev/null'),
errStream: fs.createWriteStream('/dev/null'),
ignoreReturnCode: true,
listeners: {
stdout: (data) => {
diff += data.toString();
}
}
};
let anyFailed = false;
core.startGroup('CRD Diff');
await exec.exec('diff', ['codegen-tests/cmp/crd', 'codegen-tests/definitions'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated CRD comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('Go --kindgrouping=kind Diff');
await exec.exec('diff', ['codegen-tests/cmp/go/groupbykind/customkind', 'codegen-tests/pkg/gen1/resource/customkind'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated go with --groupbykind=kind comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('Go --kindgrouping=group Diff');
await exec.exec('diff', ['codegen-tests/cmp/go/groupbykind/customkind', 'codegen-tests/pkg/gen1/resource/customkind'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated go with --groupbykind=kind comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('TypeScript Diff');
await exec.exec('diff', ['codegen-tests/cmp/typescript/versioned', 'codegen-tests/ts/gen1'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated TypeScript comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
if(anyFailed) {
core.setFailed('Diff between generated code from potential release build of grafana-app-sdk and codegen/testing/golden_generated failed');
}
- name: Bootstrap project
run: |
cd codegen-tests
grafana-app-sdk generate --nomanifest
grafana-app-sdk project component add frontend backend operator --plugin-id=codegen-tests
go mod tidy
go build cmd/operator/*.go
go build plugin/pkg/*.go
uses: ./.github/workflows/test.yml
139 changes: 1 addition & 138 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,141 +54,4 @@ jobs:
only-new-issues: true
args: --timeout 5m $(go list -f '{{.Dir}}/...' -m | tr '\n' ' ')
test:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
# go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# make test
- name: Test
# find all go.mod files and run go test against directories containing go.mod files
run: go test -v $(go list -f '{{.Dir}}/...' -m | tr '\n' ' ')
build:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
# go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
# Preflight checks
- name: Preflight checks
run: make check-go-version
# make build
- name: Build
run: go build -v cmd/grafana-app-sdk/*.go
integration-test:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: 'grafana-app-sdk'
# Go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: './grafana-app-sdk/go.mod'
# Install the CLI
- name: Install the CLI
run: cd cmd/grafana-app-sdk && go install && cd -
working-directory: ./grafana-app-sdk
# Generate code
- name: Copy test CUE files & data
run: |
mkdir -p codegen-tests && cd codegen-tests
grafana-app-sdk project init "codegen-tests"
cp ../grafana-app-sdk/codegen/cuekind/testing/*.cue kinds/
mkdir -p cmp && cp -R ../grafana-app-sdk/codegen/testing/golden_generated/* cmp/
find ./cmp -iname '*.txt' -exec bash -c 'mv -- "$1" "${1%.txt}"' bash {} \;
- name: Generate code
run: |
cd codegen-tests
grafana-app-sdk generate --kindgrouping=kind --gogenpath=pkg/gen1 --tsgenpath=ts/gen1 --crdencoding=json --nomanifest
grafana-app-sdk generate --kindgrouping=group --gogenpath=pkg/gen2 --tsgenpath=ts/gen2 --crdencoding=yaml --nomanifest
diff pkg/gen1/resource/customkind cmp/go/groupbykind/customkind > diff.txt
sed -i '/^Common subdirectories/d' diff.txt
difflines=$(wc -l diff.txt | awk '{ print $1 }')
echo "GoGroupByKindDiff=${difflines}" >> $GITHUB_ENV
- name: Compare generated code
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let diff = '';
const options = {
outStream: fs.createWriteStream('/dev/null'),
errStream: fs.createWriteStream('/dev/null'),
ignoreReturnCode: true,
listeners: {
stdout: (data) => {
diff += data.toString();
}
}
};
let anyFailed = false;
core.startGroup('CRD Diff');
await exec.exec('diff', ['codegen-tests/cmp/crd', 'codegen-tests/definitions'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated CRD comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('Go --kindgrouping=kind Diff');
await exec.exec('diff', ['codegen-tests/cmp/go/groupbykind/customkind', 'codegen-tests/pkg/gen1/resource/customkind'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated go with --groupbykind=kind comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('Go --kindgrouping=group Diff');
await exec.exec('diff', ['codegen-tests/cmp/go/groupbykind/customkind', 'codegen-tests/pkg/gen1/resource/customkind'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated go with --groupbykind=kind comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
core.startGroup('TypeScript Diff');
await exec.exec('diff', ['codegen-tests/cmp/typescript/versioned', 'codegen-tests/ts/gen1'], options);
console.log(diff);
core.endGroup();
if(diff.replace(/^Common subdirectories.*$/gm, '').trim().length > 0) {
core.error('Generated TypeScript comparison to codegen/testing/golden_generated failed, see diff for details');
anyFailed = true;
}
diff = '';
if(anyFailed) {
core.setFailed('Diff between generated code from potential release build of grafana-app-sdk and codegen/testing/golden_generated failed');
}
- name: Bootstrap project
run: |
cd codegen-tests
grafana-app-sdk generate --nomanifest
grafana-app-sdk project component add frontend backend operator --plugin-id=codegen-tests
go mod tidy
go build cmd/operator/*.go
go build plugin/pkg/*.go
uses: ./.github/workflows/test.yml
Loading

0 comments on commit 73db82e

Please sign in to comment.