Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient labels #105

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
40 changes: 40 additions & 0 deletions .github/actions/tf-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Set up TF
description: Set up terraform

inputs:
working-directory:
description: Working directory
required: false
default: terraform
wrapper:
description: Whether to use the terraform wrapper
required: false
default: 'true'
upgrade:
description: Whether to upgrade terraform
required: false
default: 'false'

runs:
using: composite
steps:
- name: Setup Terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
with:
terraform_version: 1.2.9
terraform_wrapper: ${{ inputs.wrapper }}
- name: Setup Custom Terraform Provider
run: |
curl -LO https://github.com/galargh/terraform-provider-github/releases/download/v5.25.2-rc1/terraform-provider-github_5.25.2-rc1_linux_amd64.zip
mkdir -p ~/.terraform.d/plugins/github.com/galargh/terraform-provider-github/5.25.2-rc1/linux_amd64/
unzip terraform-provider-github_5.25.2-rc1_linux_amd64.zip -d ~/.terraform.d/plugins/github.com/galargh/terraform-provider-github/5.25.2-rc1/linux_amd64/
rm terraform-provider-github_5.25.2-rc1_linux_amd64.zip
shell: bash
working-directory: ${{ inputs.working-directory }}
- name: Init Terraform
env:
UPGRADE: ${{ inputs.upgrade }}
run: |
terraform init -upgrade=${{ env.UPGRADE }}
shell: bash
working-directory: ${{ inputs.working-directory }}
8 changes: 2 additions & 6 deletions .github/workflows/apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
with:
terraform_version: 1.2.9
- name: Initialize terraform
run: terraform init
- name: Setup Terraform
uses: ./.github/actions/tf-setup
- name: Terraform Plan Download
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
- name: Setup Terraform
uses: ./.github/actions/tf-setup
with:
terraform_version: 1.2.9
terraform_wrapper: false
- name: Initialize terraform
run: terraform init -upgrade
working-directory: terraform
wrapper: false
upgrade: true
- name: Select terraform workspace
run: |
terraform workspace select "${TF_WORKSPACE_OPT}" || terraform workspace new "${TF_WORKSPACE_OPT}"
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/fix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,8 @@ jobs:
# only checking out github directory from the PR
git fetch origin "pull/${NUMBER}/head"
rm -rf github && git checkout "${SHA}" -- github
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
with:
terraform_version: 1.2.9
- name: Initialize terraform
run: terraform init
working-directory: terraform
- name: Setup Terraform
uses: ./.github/actions/tf-setup
- name: Initialize scripts
run: npm ci && npm run build
working-directory: scripts
Expand Down
19 changes: 6 additions & 13 deletions .github/workflows/plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ jobs:
run: |
git fetch origin "pull/${NUMBER}/head"
rm -rf github && git checkout "${SHA}" -- github
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
- name: Setup Terraform
uses: ./.github/actions/tf-setup
with:
terraform_version: 1.2.9
- name: Initialize terraform
run: terraform init
working-directory: terraform
working-directory: terraform
- name: Plan terraform
run: terraform plan -refresh=false -lock=false -out="${TF_WORKSPACE}.tfplan" -no-color
working-directory: terraform
Expand Down Expand Up @@ -118,14 +115,10 @@ jobs:
run: |
git fetch origin "pull/${NUMBER}/head"
rm -rf github && git checkout "${SHA}" -- github
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
- name: Setup Terraform
uses: ./.github/actions/tf-setup
with:
terraform_version: 1.2.9
terraform_wrapper: false
- name: Initialize terraform
run: terraform init
working-directory: terraform
wrapper: false
- name: Download terraform plans
uses: actions/download-artifact@v3
with:
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2.0.3
- name: Setup Terraform
uses: ./.github/actions/tf-setup
with:
terraform_version: 1.2.9
terraform_wrapper: false
- name: Initialize terraform
run: terraform init -upgrade
working-directory: terraform
wrapper: false
upgrade: true
- name: Select terraform workspace
run: |
terraform workspace select "${TF_WORKSPACE_OPT}" || terraform workspace new "${TF_WORKSPACE_OPT}"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- workflows: not to use deprecated GitHub Actions expressions anymore
- tf: to prevent destroy of membership and repository resources
- apply: find sha for plan using proper credentials
- made issue label support more efficient for large orgs

### Fixed
- links to supported resources in HOWTOs
Expand Down
2 changes: 1 addition & 1 deletion docs/ABOUT.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Running the `Sync` GitHub Action workflows refreshes the underlying terraform st
- [github_team_repository](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_repository)
- [github_team_membership](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/team_membership)
- [github_repository_file](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository_file)
- [github_issue_label](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_label)
- [github_issue_labels](https://registry.terraform.io/providers/integrations/github/latest/docs/resources/issue_labels)

# Config Fix Rules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ locals {
"github_team",
"github_branch_protection",
"github_repository_file",
"github_issue_label"
"github_issue_labels"
]
}
2 changes: 1 addition & 1 deletion scripts/__tests__/__resources__/terraform/resources.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "github_repository_file" "this" {
ignore_changes = []
}
}
resource "github_issue_label" "this" {
resource "github_issue_labels" "this" {
lifecycle {
ignore_changes = []
}
Expand Down
60 changes: 27 additions & 33 deletions scripts/__tests__/__resources__/terraform/terraform.tfstate
Original file line number Diff line number Diff line change
Expand Up @@ -2055,59 +2055,53 @@
]
},
{
"address": "github_issue_label.this[\"github-action-releaser:topic/ci\"]",
"address": "github_issue_labels.this[\"github-action-releaser\"]",
"mode": "managed",
"type": "github_issue_label",
"type": "github_issue_labels",
"name": "this",
"index": "github-action-releaser:topic/ci",
"provider_name": "registry.terraform.io/integrations/github",
"schema_version": 0,
"values": {
"repository": "github-action-releaser",
"name": "topic/ci",
"color": "#57cc2c",
"description": "Topic CI",
"url": "https://github.com/pl-strflt/github-action-releaser/labels/topic%2Fci"
},
"sensitive_values": {},
"depends_on": [
"github_repository.this"
]
},
{
"address": "github_issue_label.this[\"github-action-releaser:topic dx\"]",
"mode": "managed",
"type": "github_issue_label",
"name": "this",
"index": "github-action-releaser:topic dx",
"index": "github-action-releaser",
"provider_name": "registry.terraform.io/integrations/github",
"schema_version": 0,
"values": {
"repository": "github-action-releaser",
"name": "topic dx",
"color": "#57cc2c",
"description": "Topic DX",
"url": "https://github.com/pl-strflt/github-action-releaser/labels/topic%20dx"
"label": [
{
"name": "topic/ci",
"color": "#57cc2c",
"description": "Topic CI",
"url": "https://github.com/pl-strflt/github-action-releaser/labels/topic%2Fci"
},
{
"name": "topic dx",
"color": "#57cc2c",
"description": "Topic DX",
"url": "https://github.com/pl-strflt/github-action-releaser/labels/topic%20dx"
}
]
},
"sensitive_values": {},
"depends_on": [
"github_repository.this"
]
},
{
"address": "github_issue_label.this[\"projects-status-history:stale\"]",
"address": "github_issue_labels.this[\"projects-status-history\"]",
"mode": "managed",
"type": "github_issue_label",
"type": "github_issue_labels",
"name": "this",
"index": "projects-status-history:stale",
"provider_name": "registry.terraform.io/integrations/github",
"schema_version": 0,
"values": {
"repository": "projects-status-history",
"name": "stale",
"color": "#57cc2c",
"description": "Stale",
"url": "https://github.com/pl-strflt/projects-status-history/labels/stale"
"label": [
{
"name": "stale",
"color": "#57cc2c",
"description": "Stale",
"url": "https://github.com/pl-strflt/projects-status-history/labels/stale"
}
]
},
"sensitive_values": {},
"depends_on": [
Expand Down
4 changes: 2 additions & 2 deletions scripts/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {RepositoryBranchProtectionRule} from './src/resources/repository-branch-
import {RepositoryTeam} from './src/resources/repository-team'
import {TeamMember} from './src/resources/team-member'
import {RepositoryFile} from './src/resources/repository-file'
import {RepositoryLabel} from './src/resources/repository-label'
import {RepositoryLabels} from './src/resources/repository-labels'
import {GitHub} from './src/github'

jest.mock('./src/env', () => ({
Expand Down Expand Up @@ -67,7 +67,7 @@ global.ResourceCounts = {
[RepositoryTeam.name]: 7,
[TeamMember.name]: 2,
[RepositoryFile.name]: 1,
[RepositoryLabel.name]: 3
[RepositoryLabels.name]: 2
}
global.ResourcesCount = Object.values(global.ResourceCounts).reduce(
(a, b) => a + b,
Expand Down
90 changes: 0 additions & 90 deletions scripts/src/resources/repository-label.ts

This file was deleted.

Loading