Skip to content

Commit

Permalink
Tooling: generation for TC services / GH labels, update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Jan 29, 2024
1 parent 17184fe commit 8df93e1
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 30 deletions.
6 changes: 2 additions & 4 deletions .github/labeler-issue-triage.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# NOTE: this file is generated via 'make generate'
bug:
- 'panic:'
crash:
- 'panic:'
- 'panic:'
28 changes: 21 additions & 7 deletions .github/labeler-pull-request-triage.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

# NOTE: this file is generated via 'make generate'
dependencies:
- go.mod
- go.sum
- vendor/**/*
- changed-files:
- any-glob-to-any-file:
- go.mod
- go.sum
- vendor/**/*
documentation:
- website/**/*
- changed-files:
- any-glob-to-any-file:
- docs/**/*
- examples/**/*
tooling:
- changed-files:
- any-glob-to-any-file:
- .github/**/*
- internal/tools/**/*
- scripts/**/*
- GNUmakefile
state-migration:
- changed-files:
- any-glob-to-any-file:
- internal/services/**/migration/**/*
26 changes: 26 additions & 0 deletions .github/workflows/comment-failure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Comment Failure

on:
# This file is reused, and called from other workflows
workflow_call:

jobs:
comment-failure:
runs-on: ubuntu-latest
steps:
- name: Get run url
if: failure()
run: |
echo "gha_url=https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" >> $GITHUB_ENV
- name: Send build failure comment
if: failure()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
result-encoding: string
script: |
github.rest.issues.createComment({
issue_number: ${{ github.event.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: '<b>Build failure</b> \n\n This pull request contains a build failure which needs addressed [here](${{ env.gha_url}}) .'
})
4 changes: 4 additions & 0 deletions .github/workflows/depscheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.depscheck.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.depscheck.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/docs-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.docs-lint.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.depscheck.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
35 changes: 35 additions & 0 deletions .github/workflows/gencheck.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Generation Check

permissions:
contents: read

on:
pull_request:
types: ['opened', 'synchronize']
paths:
- '.github/workflows/gencheck.yaml'
- '**.go'

concurrency:
group: 'gencheck-${{ github.head_ref }}'
cancel-in-progress: true

jobs:
gencheck:
runs-on: [custom, linux, large]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: ./.go-version
- run: bash scripts/gogetcookie.sh
- run: make gencheck

save-artifacts-on-fail:
if: ${{ needs.gencheck.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.gencheck.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/golint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.golint.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.golint.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/provider-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.secrets-check.result }} == 'failure' || ${{ needs.provider-tests.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.secrets-check.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/tflint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.tflint.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.tflint.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/thirty-two-bit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.compatibility-32bit-test.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.compatibility-32bit-test.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.test.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.test.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
4 changes: 4 additions & 0 deletions .github/workflows/validate-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
save-artifacts-on-fail:
if: ${{ needs.validate-examples.result }} == 'failure'
uses: ./.github/workflows/save-artifacts.yaml

comment-on-fail:
if: ${{ needs.validate-examples.result }} == 'failure'
uses: ./.github/workflows/comment-failure.yaml
20 changes: 20 additions & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// NOTE: this is Generated from the Service Definitions - manual changes will be lost
// to re-generate this file, run 'make generate' in the root of the repository
var services = mapOf(
"administrativeunits" to "Administrative Units",
"approleassignments" to "App Role Assignments",
"applications" to "Applications",
"conditionalaccess" to "Conditional Access",
"directoryobjects" to "Directory Objects",
"directoryroles" to "Directory Roles",
"domains" to "Domains",
"groups" to "Groups",
"identitygovernance" to "Identity Governance",
"invitations" to "Invitations",
"policies" to "Policies",
"serviceprincipals" to "Service Principals",
"userflows" to "User Flows",
"users" to "Users"
)
17 changes: 0 additions & 17 deletions .teamcity/components/project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ import jetbrains.buildServer.configs.kotlin.Project

const val providerName = "azuread"

var services = mapOf(
"administrativeunits" to "Administrative Units",
"applications" to "Applications",
"approleassignments" to "App Role Assignments",
"conditionalaccess" to "Conditional Access",
"directoryobjects" to "Directory Objects",
"directoryroles" to "Directory Roles",
"domains" to "Domains",
"groups" to "Groups",
"identitygovernance" to "Identity Governance",
"invitations" to "Invitations",
"policies" to "Policies",
"serviceprincipals" to "Service Principals",
"userflows" to "User Flows",
"users" to "Users"
)

fun AzureAD(environment: String, config : ClientConfiguration) : Project {
return Project{
var pullRequestBuildConfig = pullRequestBuildConfiguration(environment, config)
Expand Down
10 changes: 10 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ fmt:
fmtcheck:
@sh "$(CURDIR)/scripts/gofmtcheck.sh"

generate:
go generate ./internal/services/...
go generate ./internal/provider/

goimports:
@echo "==> Fixing imports code with goimports..."
goimports -local "github.com/hashicorp/terraform-provider-azuread" -w internal/
Expand Down Expand Up @@ -69,6 +73,12 @@ depscheck:
@git diff --compact-summary --exit-code -- vendor || \
(echo; echo "Unexpected difference in vendor/ directory. Run 'go mod vendor' command or revert any go.mod/go.sum/vendor changes and commit."; exit 1)

gencheck:
@echo "==> Generating..."
@make generate
@echo "==> Comparing generated code to committed code..."
@git diff --compact-summary --exit-code -- ./ || \
(echo; echo "Unexpected difference in generated code. Run 'make generate' to update the generated code and commit."; exit 1)

test: fmtcheck
@TEST=$(TEST) ./scripts/run-test.sh
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/hashicorp/terraform-provider-azuread/internal/services/users"
)

//go:generate go run ../tools/generator-services/main.go -path=../../

func SupportedTypedServices() []sdk.TypedServiceRegistration {
return []sdk.TypedServiceRegistration{
applications.Registration{},
Expand Down
2 changes: 1 addition & 1 deletion internal/services/conditionalaccess/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "ConditionalAccess"
return "Conditional Access"
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
Expand Down
2 changes: 1 addition & 1 deletion internal/services/directoryobjects/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "DirectoryObjects"
return "Directory Objects"
}

// WebsiteCategories returns a list of categories which can be used for the sidebar
Expand Down
23 changes: 23 additions & 0 deletions internal/tools/generator-services/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Generator: Services

Each Service Definition contains metadata (such as the Display Name & Website Categories) required in other parts of the codebase, for easier grouping.

This generator takes that metadata and uses it to generate two things:

1. Website Categories - which validates the categories used in the website exist, required for website deployments to happen.
2. Service Definitions - generates the list of services used to run the Acceptance Tests
3. GitHub Labels - generates the list of tags which should be assigned to a pull request when files within this path are changed.

This is run via go:generate whenever the "SupportedServices" array is changed so that this is kept up-to-date.

## Example Usage

```
go run main.go -path=../../path/to/root-directory
```

## Arguments

* `help` - Show help?

* `path` - The Relative Path to the root of the repository
Loading

0 comments on commit 8df93e1

Please sign in to comment.