Skip to content

Init Process with CI #36

Init Process with CI

Init Process with CI #36

Workflow file for this run

name: DynamoDB-CI
on:
push:
branches:
- feat/GOOGLEPS04-68
pull_request:
types:
- opened
- edited
- closed
- synchronize
branches:
- feat/GOOGLEPS04-68
release:
types: [ published ]
env:
LOCATION: ${{ secrets.LOCATION }}
PROJECT_ID : ${{ secrets.PROJECT_ID }}
APP_VERSION: ${{ github.sha }}
INSTANCE_ID: ${{ secrets.INSTANCE_ID }}
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
QUERY_LIMIT: ${{ secrets.QUERY_LIMIT }}
DYNAMODB_QUERY_LIMIT: ${{ secrets.DYNAMODB_QUERY_LIMIT }}
jobs:
golangLint:
name: Lint Scan
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: true
- name: golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint --version
- name: Run Golangci Lint
id: lint
run: |
golangci-lint run --timeout 5m --issues-exit-code 0 --out-format=tab > lint_results_table.md
if [ -s lint_results_table.md ]; then
echo "Issues found"
echo "lint_flag=true" >> "$GITHUB_OUTPUT"
else
echo "No issues found"
fi
- name: Lint Error Comment on PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request' && steps.lint.outputs.lint_flag
with:
script: |
const fs = require('fs');
const table = fs.readFileSync('lint_results_table.md', 'utf8');
const commentMessage = 'Please fix the above lint and re-run the job.';
// Comment on the pull request using the github context
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Golang Lint Detected\n\n${table}\n\n${commentMessage}`,
})
.then(() => {
console.log('Commented on the pull request successfully. Please review and resolve the Lint Comment');
// process.exit(1); // Exit the script with a failure status to fail the GitHub workflow
})
.catch((error) => {
console.error('Error commenting on the pull request:', error);
// process.exit(1);
});
compileTest:
name: Unit Test & Integration Test
runs-on: ubuntu-latest
permissions:
contents: 'write'
id-token: 'write'
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ env.PROJECT_ID }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_DEPLOY }}
create_credentials_file: true
export_environment_variables: true
- name: Run unit test cases
id: unit_test
run: |
envsubst < config.yaml > config.yaml.tmp && mv config.yaml.tmp config.yaml
cat config.yaml
go mod tidy
go test -v -short ./{/api/v1,/initializer,/storage,/utils,/service/services,/service/spanner} -coverprofile=cover.out | tee -a ${GITHUB_WORKSPACE}/unit_test_result.txt ; (exit ${PIPESTATUS[0]})
go tool cover -func cover.out | grep total: >> ${GITHUB_WORKSPACE}/unit_test_result.txt
- name: Comment unit test result on PR
uses: actions/github-script@v7
if: ${{ success() || failure() }}
continue-on-error: true
with:
script: |
const fs = require('fs');
const filePath = `${process.env.GITHUB_WORKSPACE}/unit_test_result.txt`;
const unit_test_result = fs.readFileSync(filePath, 'utf8');
// Comment on the pull request using the github context
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### Unit test result\n\n${unit_test_result}\n`,
})
.then(() => {
console.log('Commented on the pull request successfully.');
// process.exit(1); // Exit the script with a failure status to fail the GitHub workflow
})
.catch((error) => {
console.error('Error commenting on the pull request:', error);
// process.exit(1);
});
- name: Run integration test cases
id: integration_test
env:
INTEGRATION_TEST_CRED_PATH: ${{ secrets.INTEGRATION_TEST_CRED_PATH }}
run: |
envsubst < config.yaml > config.yaml.tmp && mv config.yaml.tmp config.yaml
go run "${GITHUB_WORKSPACE}/integrationtest/setup.go" setup
go test "${GITHUB_WORKSPACE}/integrationtest/api_test.go" | tee -a ${GITHUB_WORKSPACE}/integration_test_result.txt
go run "${GITHUB_WORKSPACE}/integrationtest/setup.go" teardown
- name: Comment integration test result on PR
uses: actions/github-script@v7
if: ${{ success() || failure() }}
continue-on-error: true
with:
script: |
const fs = require('fs');
const filePath = `${process.env.GITHUB_WORKSPACE}/integration_test_result.txt`;
const integration_test_result = fs.readFileSync(filePath, 'utf8');
// Extract and format the integration test result
const lines = integration_test_result.split('\n');
let formatted_result = '### Integration Test Result\n\n';
formatted_result += '| Test Package | Status | Duration |\n';
formatted_result += '|--------------------------|--------|-----------|\n';
lines.forEach((line, index) => {
const match = line.match(/^(ok|FAIL)\s+(\S+)\s+([\d\.]+s)$/);
if (match) {
const status = match[1];
let packageName = match[2];
const duration = match[3];
if(index === 0) {
packageName = "proxy-adaptor-integration-tests";
} else {
packageName = "cassandra-adaptor-integration-tests";
}
formatted_result += `| ${packageName} | ${status} | ${duration} |\n`;
}
});
// Comment on the pull request using the github context
github.rest.issues.createComment({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${formatted_result}\n\n${integration_test_result}\n`,
})
.then(() => {
console.log('Commented on the pull request successfully.');
// process.exit(1); // Exit the script with a failure status to fail the GitHub workflow
})
.catch((error) => {
console.error('Error commenting on the pull request:', error);
// process.exit(1);
});
sonarScan:
name: Sonar Cloud Scan
runs-on: ubuntu-latest
permissions:
contents: 'write'
id-token: 'write'
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v2'
with:
project_id: ${{ env.PROJECT_ID }}
workload_identity_provider: ${{ secrets.WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.SERVICE_ACCOUNT_DEPLOY }}
create_credentials_file: true
export_environment_variables: true
- name: Run unit test cases
id: unit_test
run: |
envsubst < config.yaml > config.yaml.tmp && mv config.yaml.tmp config.yaml
cat config.yaml
go mod tidy
go test -v -short ./{/api/v1,/initializer,/config,/storage,/utils,/service/services,/service/spanner} -coverprofile=cover.out
go tool cover -func cover.out
- name: Set up Docker
uses: docker/setup-buildx-action@v3
- name: Analyze with SonarCloud
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=cldcvr
-Dsonar.projectKey=ollionorg_dynamodb-adapter-fork
-Dproject.settings=sonar-project.properties
-Dsonar.go.coverage.reportPaths=cover.out