Giter Club home page Giter Club logo

check-members's Introduction

Check Members

This action runs on pull requests to count GitHub organization members and membership written in terraform files.

Examples

Example comment made by the action

Environment variables

ACCESS_TOKEN

Required. This token needs to have read:org scope to read organization information by octokit.

See https://docs.github.com/en/rest/reference/orgs#get-an-organization

TERRAFORM_JSON_FILE_PATH

Required. The json file from running the command terraform show --json | jq.

ORGANIZATION_NAME

Required. This organization name for which you want to count seats.

Outputs

filled_seats

Seats that membership used.

max_seats

Max seats an organization can use.

members_in_terraform

Total number of membership in the github_membership and github_repository_collaborator resources written in the terraform file.

non_existing_members

Members which are in terraform do not exist in GitHub.

Example usage

  • Note: This action should be used with setup-terraform step. The terraform_wrapper flag in the setup-terraform step should be set to false.
on: [pull_request]

jobs:
  job:
    runs-on: ubuntu-latest
    name: A job to show seats
    steps:
      - uses: actions/checkout@v2

      - uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: 1.3.9
          terraform_wrapper: false

      - name: Terraform init
        run: terraform init

      - name: Terraform plan
        run: terraform plan -out plan-binary

      - name: Terraform show --json
        run:  terraform show --json plan-binary | jq >> terraform-json.json

      - name: Set up ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 2.7

      - name: Count seats and members
        id: seats_members
        uses: M-Yamashita01/[email protected]
        env:
          ACCESS_TOKEN: ${{ secrets.GITHUB_ADMIN_ACCESS_TOKEN }}
          TERRAFORM_JSON_FILE_PATH: '${{ github.workspace }}/terraform-json.json'
          ORGANIZATION_NAME: 'organization_name'

      - name: Post comments
        uses: actions/github-script@v5
        with:
          script: |
            var output = `Current seats in organization and members in terraform files.\n
              ・Seats that membership used:: ${{ steps.seats_members.outputs.filled_seats }}\n
              ・Max seats an organization can use: ${{ steps.seats_members.outputs.max_seats }}\n
              ・Total number of membership in terraform files: ${{ steps.seats_members.outputs.members_in_terraform }}\n\n
            `
            const numberOfSeatsInShortage = ${{ steps.seats_members.outputs.members_in_terraform }} - ${{ steps.seats_members.outputs.max_seats }}
            var additional_message = `There is no shortage of seats.\n`
            if (numberOfSeatsInShortage > 0) {
              additional_message = `There are ${numberOfSeatsInShortage} seats missing. Please add seats.\n`
            }

            var notify_non_existing_member_message = ``
            const non_existing_members = "${{ steps.seats_members.outputs.non_existing_members }}"
            if (non_existing_members.length > 0) {
              notify_non_existing_member_message = `Some members in terraform files do not exist. Please check the members.\n
              ・Non-existing members: ${non_existing_members}.\n\n
              `
            }

            output += additional_message
            output += notify_non_existing_member_message
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: output
            })

check-members's People

Contributors

m-yamashita01 avatar

Stargazers

Yusuke Iwaki avatar

Watchers

 avatar

check-members's Issues

Count the username written in comment incorrectly.

When the comment out codes such as the following codes is written in terraform files, this action counts the username incorrectly.

# resource "github_membership" "membership_for_some_user" {
#  username = "SomeUser"
#  role     = "member"
#}

Read github members from all terraform files.

In this action, it reads specified terraform files.
But when github_membership or github_repository_collaborator resources are written in terraform files other than the specified one
Therefore, we want to read the resources from all terraform files.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.