Skip to content

Bump the all group across 1 directory with 2 updates #670

Bump the all group across 1 directory with 2 updates

Bump the all group across 1 directory with 2 updates #670

Workflow file for this run

name: Build PR
on:
pull_request:
branches:
- main
jobs:
check:
name: Go Workspace Check
runs-on: ubuntu-latest
# Exlude dependabot from this check--it can't run make update-workspace,
# We'll just force the next PR author to do it instead for now
if: ${{ github.actor != 'dependabot[bot]' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set go version
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Update workspace
run: make update-workspace
- name: Check for go mod & workspace changes
run: |
if ! git diff --exit-code --quiet; then
echo "Changes detected:"
git diff
echo "Please run 'make update-workspace' and commit the changes."
exit 1
fi
lint:
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 lint
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.60.3
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