Skip to content

Fix working-directory. #46

Fix working-directory.

Fix working-directory. #46

Workflow file for this run

name: Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
# git checkout
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Go env
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
# make test
- name: Test
run: go test -v ./...
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: "1.22"
# 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
grafana-app-sdk generate --kindgrouping=group --gogenpath=pkg/gen2 --tsgenpath=ts/gen2 --crdencoding=yaml
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
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