Skip to content

Commit 82e2d47

Browse files
committed
Restructure action
1 parent 7ece193 commit 82e2d47

34 files changed

+54426
-6595
lines changed

.github/codeql/codeql-config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: CodeQL Configuration
2+
3+
paths-ignore:
4+
- node_modules
5+
- dist
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: CodeQL
22

33
on:
4-
pull_request:
4+
push:
55
branches:
66
- main
7-
push:
7+
pull_request:
88
branches:
99
- main
1010
schedule:
11-
- cron: '31 7 * * 3'
11+
- cron: '30 1 * * 4'
1212

1313
permissions:
1414
actions: read
@@ -25,7 +25,7 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
language:
28-
- TypeScript
28+
- javascript
2929

3030
steps:
3131
- name: Checkout
@@ -37,7 +37,6 @@ jobs:
3737
uses: github/codeql-action/init@v3
3838
with:
3939
languages: ${{ matrix.language }}
40-
source-root: src
4140

4241
- name: Autobuild
4342
id: autobuild
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Continuous Delivery
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- main
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
release:
16+
name: Release Version
17+
runs-on: ubuntu-latest
18+
19+
if: |
20+
github.event_name == 'workflow_dispatch' ||
21+
(github.event.pull_request.merged == true &&
22+
startsWith(github.head_ref, 'dependabot/') == false)
23+
24+
steps:
25+
- name: Checkout
26+
id: checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-tags: true
30+
31+
- name: Tag
32+
id: tag
33+
uses: issue-ops/semver@v2
34+
with:
35+
manifest-path: package.json
36+
workspace: ${{ github.workspace }}
37+
ref: main
38+
39+
- name: Create Release
40+
id: release
41+
uses: issue-ops/releaser@v2
42+
with:
43+
tag: v${{ steps.tag.outputs.version }}

.github/workflows/ci.yml renamed to .github/workflows/continuous-integration.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ on:
44
pull_request:
55
branches:
66
- main
7-
push:
8-
branches:
9-
- main
7+
workflow_dispatch:
108

119
permissions:
10+
checks: write
1211
contents: read
1312

1413
jobs:
15-
test-typescript:
16-
name: TypeScript Tests
14+
continuous-integration:
15+
name: Continuous Integration
1716
runs-on: ubuntu-latest
1817

1918
steps:
@@ -29,17 +28,17 @@ jobs:
2928
cache: npm
3029

3130
- name: Install Dependencies
32-
id: npm-ci
31+
id: install
3332
run: npm ci
3433

3534
- name: Check Format
36-
id: npm-format-check
35+
id: format-check
3736
run: npm run format:check
3837

3938
- name: Lint
40-
id: npm-lint
39+
id: lint
4140
run: npm run lint
4241

4342
- name: Test
44-
id: npm-ci-test
43+
id: test
4544
run: npm run ci-test

README.md

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
# GHEC billing and usage reporting
1+
# GitHub Enterprise Cloud Billing and Usage Reporting
22

3-
This action extracts billing and usage numbers from an enterprise and creates a report as a GitHub issue in the repository where it is running.
3+
This action extracts billing and usage numbers from a GitHub enterprise and
4+
creates a report as an issue in the repository where it is running.
45

5-
## Inputs and environment variables
6+
## Inputs
67

7-
### Inputs
8+
- **`enterprise_slug`**: The
9+
[slug](https://en.wikipedia.org/wiki/Clean_URL#Slug) of the enterprise you
10+
wish to query
11+
- **`enterprise_token`**: The token that has access to the enterprise you wish
12+
to query
813

9-
- **enterprise**: the [slug](https://en.wikipedia.org/wiki/Clean_URL#Slug) of the enterprise you wish to query.
10-
- **title**: the title of the report issue. This title will be used as the issue title and as the top heading of the issue body with the date of the run appended to it. By [default](https://github.com/ActionsDesk/ghec-enterprise-reporting/blob/main/action.yml) the title will have the value `GHEC Usage Report`.
14+
This should be created as a
15+
[GitHub Actions secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository)
16+
in the repository that is using this action. This token should have the
17+
following scopes:
1118

12-
### Environment variables
19+
- `admin:enterprise`
20+
- `admin:org`
1321

14-
Environment variables are meant to be used in your workflow file. Take a look at our [docs for the proper workflow file syntax](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions).
22+
- **`github_token`**: The token that will be used to create the issue (defaults
23+
to the
24+
[automatic token](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication)
25+
provided by GitHub)
26+
- **`issue_title`**: The title of the report issue (default:
27+
`GHEC Usage Report`)
1528

16-
When dealing with token please take extra care and use the secure store available in every GitHub repo. Once the value has been added to the secure store you can access it in your workflow file by using `${{secrets.SECURE_VALUE}}` syntax. Here's a [sample workflow](#using-this-action) file as an example.
29+
This title will be used as the issue title, as well as the top heading of the
30+
issue body with the date of the run appended to it.
1731

18-
#### ENTERPRISE_TOKEN
32+
## Usage
1933

20-
A token that has access to the enterprise level data for the enterprise you wish to query. To create a token go to the settings on the account that should manage it.
21-
22-
It's important that this token have the following OAuth scopes:
23-
24-
- admin:enterprise
25-
- admin:org
26-
27-
This token needs to be added to the secrets store of the repository that is using it. Take a look at our docs for more on [using secrets with GitHub Actions](https://docs.github.com/en/actions/getting-started-with-github-actions/security-hardening-for-github-actions#using-secrets).
28-
Take a look at our docs for more information about [personal access tokens](https://docs.github.com/en/developers/apps/about-apps#personal-access-tokens) and [OAuth scopes](https://docs.github.com/en/developers/apps/scopes-for-oauth-apps).
29-
30-
#### GITHUB_TOKEN
31-
32-
This is the GitHub token that is available in the Action's context. This token will be used to create an issue with the generated report. You don't have to do anything more to use this.
33-
34-
## Using this action
35-
36-
A great way to using this action is with a scheduler. Here's an example workflow file that will run our action on the 28th day of the month, every month:
34+
A great way to using this action is with a scheduler. Here's an example workflow
35+
file that will run our action on the 28th day of the month, every month:
3736

3837
```yaml
3938
on:
@@ -42,18 +41,74 @@ on:
4241

4342
jobs:
4443
report:
44+
name: Report on GitHub Enterprise Cloud Usage
4545
runs-on: ubuntu-latest
4646

4747
steps:
48-
- uses: actionsdesk/ghec-enterprise-reporting@v2
48+
- name: Generate Report
49+
id: report
50+
uses: ActionsDesk/ghec-enterprise-reporting@vX.Y.Z # Replace with the latest version
4951
with:
50-
enterprise: 'awesome-enterprise'
51-
title: 'Much enterprise reporting'
52-
env:
53-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54-
ENTERPRISE_TOKEN: ${{secrets.ENTERPRISE_TOKEN}}
52+
enterprise_slug: awesome-enterprise
53+
enterprise_token: ${{ secrets.ENTERPRISE_TOKEN }}
54+
issue_title: My Enterprise Report
55+
```
56+
57+
## Example Output
58+
59+
The following markdown will be generated in the issue body:
60+
61+
```markdown
62+
This usage report is for the **ENTERPRISE_SLUG** GHEC account.
63+
64+
## AssetPacks
65+
66+
Total Purchased: 6
67+
68+
## Enterprise Organizations
69+
70+
| Name | Login | Billing Email |
71+
| -------- | --------- | ------------- |
72+
| ORG_NAME | ORG_LOGIN | BILLING_EMAIL |
73+
74+
## Bandwidth
75+
76+
| Usage | Quota | Usage Percentage |
77+
| ----- | ----- | ---------------- |
78+
| 0 | 0 | 0 |
79+
80+
## Storage
81+
82+
| Usage | Quota | Usage Percentage |
83+
| ----- | ----- | ---------------- |
84+
| 0 | 0 | 0 |
85+
86+
## Licenses
87+
88+
| Total Licenses | All Licensable Users Count | Total Available Licenses |
89+
| -------------- | -------------------------- | ------------------------ |
90+
| 0 | 0 | 0 |
91+
92+
## Actions Usage
93+
94+
| Minutes Used | Paid Minutes Used | Included Minutes |
95+
| ------------ | ----------------- | ---------------- |
96+
| 0 | 0 | 0 |
97+
98+
## Packages Usage
99+
100+
| Total GB Bandwidth Used | Total Paid GB Bandwidth Used | Included GB Bandwidth |
101+
| ----------------------- | ---------------------------- | --------------------- |
102+
| 0 | 0 | 0 |
103+
104+
## Shared Storage Usage
105+
106+
| Days Left In Cycle | Estimated Paid Storage For Month | Estimated Storage For Month |
107+
| ------------------ | -------------------------------- | --------------------------- |
108+
| 0 | 0 | 0 |
55109
```
56110

57111
## Contributing
58112

59-
All contributions are welcome, from issues to pull requests. Please take a look at our [CONTRIBUTION.md](CONTRIBUTION.md) file for details!
113+
All contributions are welcome, from issues to pull requests. Please take a look
114+
at our [CONTRIBUTION.md](CONTRIBUTION.md) file for details!

__fixtures__/@actions/core.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type * as core from '@actions/core'
2+
import { jest } from '@jest/globals'
3+
4+
export const debug = jest.fn<typeof core.debug>()
5+
export const error = jest.fn<typeof core.error>()
6+
export const info = jest.fn<typeof core.info>()
7+
export const getInput = jest.fn<typeof core.getInput>()
8+
export const setOutput = jest.fn<typeof core.setOutput>()
9+
export const setFailed = jest.fn<typeof core.setFailed>()
10+
export const warning = jest.fn<typeof core.warning>()

__fixtures__/@actions/github.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as octokit from '../@octokit/rest.js'
2+
3+
export const getOctokit = () => octokit
4+
5+
export const context = {
6+
repo: {
7+
owner: 'ActionsDesk',
8+
repo: 'ghec-enterprise-reporting'
9+
},
10+
payload: {
11+
action: 'workflow_dispatch',
12+
organization: {
13+
login: 'ActionsDesk'
14+
},
15+
repository: {
16+
full_name: 'ActionsDesk/ghec-enterprise-reporting',
17+
name: 'ghec-enterprise-reporting',
18+
owner: {
19+
login: 'ActionsDesk'
20+
},
21+
url: 'https://api.github.com/repos/ActionsDesk/ghec-enterprise-reporting'
22+
}
23+
},
24+
eventName: 'workflow_dispatch'
25+
}

__fixtures__/@octokit/rest.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { jest } from '@jest/globals'
2+
import { Endpoints } from '@octokit/types'
3+
4+
export const graphql = jest.fn()
5+
export const paginate = jest.fn()
6+
export const rest = {
7+
issues: {
8+
create:
9+
jest.fn<
10+
() => Promise<
11+
Endpoints['POST /repos/{owner}/{repo}/issues']['response']
12+
>
13+
>()
14+
}
15+
}
16+
17+
// Enterprise Plugin Methods
18+
export const billing = {
19+
getGithubActionsBillingGhe: jest.fn(),
20+
getGithubPackagesBillingGhe: jest.fn(),
21+
getSharedStorageBillingGhe: jest.fn()
22+
}

0 commit comments

Comments
 (0)