diff --git a/.github/workflows/__shared-ci.yml b/.github/workflows/__shared-ci.yml index 3797f20..a0fef63 100644 --- a/.github/workflows/__shared-ci.yml +++ b/.github/workflows/__shared-ci.yml @@ -11,6 +11,10 @@ jobs: needs: linter uses: ./.github/workflows/__test-action-matrix-outputs.yml + test-action-repository-owner-is-organization: + needs: linter + uses: ./.github/workflows/__test-action-repository-owner-is-organization.yml + test-action-slugify: needs: linter uses: ./.github/workflows/__test-action-slugify.yml diff --git a/.github/workflows/__test-action-repository-owner-is-organization.yml b/.github/workflows/__test-action-repository-owner-is-organization.yml new file mode 100644 index 0000000..d9c2128 --- /dev/null +++ b/.github/workflows/__test-action-repository-owner-is-organization.yml @@ -0,0 +1,21 @@ +name: Internal - Tests for repository-owner-is-organization action + +on: + workflow_call: + +jobs: + tests: + name: Tests for repository-owner-is-organization action + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - id: repository-owner-is-organization + uses: ./actions/repository-owner-is-organization + + - name: Check repository-owner-is-organization outputs + run: | + if [ "${{ steps.repository-owner-is-organization.outputs.is-organization }}" != 'true' ]; then + echo "repository-owner-is-organization outputs result is not valid" + exit 1 + fi diff --git a/actions/repository-owner-is-organization/README.md b/actions/repository-owner-is-organization/README.md new file mode 100644 index 0000000..f8d105e --- /dev/null +++ b/actions/repository-owner-is-organization/README.md @@ -0,0 +1,40 @@ + + + + +# GitHub Action: Repository owner is organization + + + + + + +Action to check if the repository owner is an organization. + + + + + + +```yaml +- uses: hoverkraft-tech/ci-github-common/actions/repository-owner-is-organization@v0.7.5 + with: +``` + + + + +| **Input** | **Description** | **Default** | **Required** | +| ----------------------------- | ------------------------------------ | -------------------------------- | ------------ | +| **github-token** | GitHub token for fetching users API. | ${{ github.token }} | **false** | + + + + +| **Output** | **Description** | **Default** | **Required** | +| ---------------------------- | ------------------------------------------------------------------------ | ----------- | ------------ | +| is-organization | The boolean value indicating if the repository owner is an organization. | undefined | undefined | + + + + diff --git a/actions/repository-owner-is-organization/action.yml b/actions/repository-owner-is-organization/action.yml new file mode 100644 index 0000000..fcd874e --- /dev/null +++ b/actions/repository-owner-is-organization/action.yml @@ -0,0 +1,31 @@ +name: "Repository owner is organization" +description: "Action to check if the repository owner is an organization." +author: Hoverkraft +branding: + icon: users + color: gray-dark + +inputs: + github-token: + description: "GitHub token for fetching users API." + default: ${{ github.token }} + required: false + +outputs: + is-organization: + description: "The boolean value indicating if the repository owner is an organization." + value: "${{ steps.check-org.outputs.is-organization }}" + +runs: + using: "composite" + steps: + - id: check-org + run: | + OWNER_TYPE=$(curl -s -H "Authorization: token ${{ inputs.github-token }}" \ + "https://api.github.com/users/${{ github.repository_owner }}" | jq -r .type) + + if [ "$OWNER_TYPE" = "Organization" ]; then + echo "is-organization=true" >> "$GITHUB_OUTPUT" + fi + + shell: bash