Skip to content

Commit 6d7f833

Browse files
fix: Fix workflows (#2206)
* Run only acceptance tests in test acceptance * Revert sweepers, comments, and unified tests setup * Fix workflow config * Skip tests due to introduced breaking change in #2150 * Fix workflow config
1 parent 64335e7 commit 6d7f833

24 files changed

+129
-98
lines changed

.github/workflows/test-acceptance.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/test-unit-and-integration.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Run secret-dependent integration tests only after /ok-to-test approval
2+
on:
3+
repository_dispatch:
4+
types: [ok-to-test-command]
5+
pull_request:
6+
name: tests
7+
8+
jobs:
9+
all-tests:
10+
name: all-tests
11+
runs-on: ubuntu-latest
12+
if: (github.event_name == 'repository_dispatch') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
13+
steps:
14+
- id: verify_sha_input
15+
if: github.event_name == 'repository_dispatch'
16+
run: |
17+
echo \"${{ github.event.client_payload.pull_request.head.sha }}\"
18+
echo \"${{ github.event.client_payload.slash_command.args.named.sha }}\"
19+
SHAINPUT=$(echo ${{github.event.client_payload.slash_command.args.named.sha}} | cut -c1-7)
20+
if [ ${#SHAINPUT} -le 6 ]; then echo "error::input sha not at least 7 characters long" ; exit 1
21+
else echo "done"
22+
fi
23+
SHAHEAD=$(echo ${{github.event.client_payload.pull_request.head.sha}} | cut -c1-7)
24+
echo ${#SHAINPUT}
25+
echo ${#SHAHEAD}
26+
if [ "${SHAHEAD}" != "${SHAINPUT}" ]; then echo "sha input from slash command does not equal the head sha" ; exit 1
27+
else echo "shas are equal"
28+
fi
29+
30+
- uses: actions/checkout@v3
31+
32+
- uses: actions/setup-go@v4
33+
with:
34+
go-version-file: ./go.mod
35+
cache: false
36+
37+
- name: Install dependencies
38+
run: make dev-setup
39+
40+
- name: Create and populate .snowflake/config file
41+
id: create_config
42+
run: mkdir $HOME/.snowflake && echo "${{ secrets.SNOWFLAKE_CONFIG_FILE }}" > $HOME/.snowflake/config
43+
44+
- run: make test
45+
if: steps.create_config.conclusion == 'success'
46+
47+
- run: make test-acceptance
48+
if: steps.create_config.conclusion == 'success'
49+
50+
- name: sweepers cleanup
51+
if: ${{ always() }}
52+
run: echo y | make sweep
53+
54+
- name: find comment
55+
if: ${{ always() }}
56+
uses: peter-evans/find-comment@v2
57+
id: fc
58+
with:
59+
issue-number: ${{ github.event.pull_request.number || github.event.client_payload.pull_request.number }}
60+
comment-author: 'github-actions[bot]'
61+
body-includes: Integration tests ran for
62+
63+
- name: create or update comment
64+
if: ${{ always() }}
65+
uses: peter-evans/create-or-update-comment@v2
66+
with:
67+
issue-number: ${{ github.event.pull_request.number || github.event.client_payload.pull_request.number }}
68+
comment-id: ${{ steps.fc.outputs.comment-id }}
69+
body: |
70+
Integration tests ${{ job.status }} for [${{ github.event.client_payload.slash_command.args.named.sha || github.event.pull_request.head.sha }}](https://github.com/Snowflake-Labs/terraform-provider-snowflake/actions/runs/${{ github.run_id }})
71+
72+
- name: set fork job status
73+
uses: actions/github-script@v6
74+
if: ${{ always() }}
75+
id: update_check_run
76+
env:
77+
number: ${{ github.event.client_payload.pull_request.number }}
78+
job: ${{ github.job }}
79+
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
80+
conclusion: ${{ job.status }}
81+
sha: ${{ github.event.client_payload.slash_command.args.named.sha }}
82+
event_name: ${{ github.event_name }}
83+
with:
84+
github-token: ${{ secrets.GITHUB_TOKEN }}
85+
script: |
86+
if (process.env.event_name !== 'repository_dispatch') {
87+
console.log("Not repository_dispatch... nothing to do!");
88+
return process.env.event_name;
89+
}
90+
const ref = process.env.sha;
91+
const { data: checks } = await github.rest.checks.listForRef({
92+
...context.repo,
93+
ref
94+
});
95+
const check = checks.check_runs.filter(c => c.name === process.env.job);
96+
console.log(check);
97+
const { data: result } = await github.rest.checks.update({
98+
...context.repo,
99+
check_run_id: check[0].id,
100+
status: 'completed',
101+
conclusion: process.env.conclusion
102+
});
103+
return result;

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test: ## run unit and integration tests
6666
go test -v -cover -timeout=30m ./...
6767

6868
test-acceptance: ## run acceptance tests
69-
TF_ACC=1 go test -v -cover -timeout=30m ./...
69+
TF_ACC=1 go test -run "^TestAcc_" -v -cover -timeout=30m ./...
7070

7171
build-local: ## build the binary locally
7272
go build -o $(BASE_BINARY_NAME) .
@@ -100,4 +100,4 @@ run-generator-%: ./pkg/sdk/%_def.go ## Run go generate on given object definitio
100100
go generate $<
101101
go generate ./pkg/sdk/$*_dto_gen.go
102102

103-
.PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance tools uninstall-tf
103+
.PHONY: build-local clean-generator-poc dev-setup dev-cleanup docs docs-check fmt fmt-check fumpt help install lint lint-fix mod mod-check pre-push pre-push-check sweep test test-acceptance uninstall-tf

pkg/datasources/current_role_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
77
)
88

9-
func TestAccCurrentRole(t *testing.T) {
9+
func TestAcc_CurrentRole(t *testing.T) {
1010
resource.ParallelTest(t, resource.TestCase{
1111
Providers: providers(),
1212
Steps: []resource.TestStep{

pkg/datasources/external_tables_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestAcc_ExternalTables(t *testing.T) {
1414
if _, ok := os.LookupEnv("SKIP_EXTERNAL_TABLE_TESTS"); ok {
15-
t.Skip("Skipping TestAccExternalTable")
15+
t.Skip("Skipping TestAcc_ExternalTables")
1616
}
1717

1818
databaseName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

pkg/datasources/system_generate_scim_access_token_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestAcc_SystemGenerateSCIMAccessToken(t *testing.T) {
1414
if _, ok := os.LookupEnv("SKIP_SCIM_INTEGRATION_TESTS"); ok {
15-
t.Skip("Skipping TestAccScimIntegration")
15+
t.Skip("Skipping TestAcc_SystemGenerateSCIMAccessToken")
1616
}
1717

1818
scimIntName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

pkg/datasources/users_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1010
)
1111

12-
func TestAccUsers(t *testing.T) {
12+
func TestAcc_Users(t *testing.T) {
1313
userName := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
1414
resource.ParallelTest(t, resource.TestCase{
1515
Providers: providers(),

pkg/resources/api_integration_acceptance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestAcc_ApiIntegration(t *testing.T) {
1515
if _, ok := os.LookupEnv("SKIP_API_INTEGRATION_TESTS"); ok {
16-
t.Skip("Skipping TestAccApiIntegration")
16+
t.Skip("Skipping TestAcc_ApiIntegration")
1717
}
1818

1919
apiIntNameAWS := strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

pkg/resources/database_acceptance_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestAcc_DatabaseWithUnderscore(t *testing.T) {
1515
if _, ok := os.LookupEnv("SKIP_DATABASE_TESTS"); ok {
16-
t.Skip("Skipping TestAccDatabase")
16+
t.Skip("Skipping TestAcc_DatabaseWithUnderscore")
1717
}
1818

1919
prefix := "_" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))
@@ -36,7 +36,7 @@ func TestAcc_DatabaseWithUnderscore(t *testing.T) {
3636

3737
func TestAcc_Database(t *testing.T) {
3838
if _, ok := os.LookupEnv("SKIP_DATABASE_TESTS"); ok {
39-
t.Skip("Skipping TestAccDatabase")
39+
t.Skip("Skipping TestAcc_Database")
4040
}
4141

4242
prefix := "tst-terraform" + strings.ToUpper(acctest.RandStringFromCharSet(10, acctest.CharSetAlpha))

0 commit comments

Comments
 (0)