Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Integration tests]: manually get the current commit for the action when bootstrapping the project. #405

Merged
merged 10 commits into from
Sep 18, 2024
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
Loading