Skip to content

Commit

Permalink
Merge pull request #269 from magefile/octokit
Browse files Browse the repository at this point in the history
use Octokit client to check mage release
  • Loading branch information
crazy-max authored Jan 28, 2023
2 parents d4baea2 + 140800c commit 67646e5
Show file tree
Hide file tree
Showing 15 changed files with 814 additions and 38 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
uses: docker/bake-action@v2
with:
targets: test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Upload coverage
uses: codecov/codecov-action@v3
Expand Down
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ___
* [Usage](#usage)
* [Customizing](#customizing)
* [inputs](#inputs)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Using on GHES](#using-on-ghes)
* [License](#license)

## Usage
Expand Down Expand Up @@ -58,28 +58,42 @@ jobs:
Following inputs can be used as `step.with` keys

| Name | Type | Default | Description |
|---------------|---------|-----------|----------------------------------|
| `version` | String | `latest` | Mage version. Example: `v1.9.0` |
| `args` | String | | Arguments to pass to Mage |
| `workdir` | String | `.` | Working directory (below repository root) |
| Name | Type | Default | Description |
|-----------|--------|----------|-------------------------------------------|
| `version` | String | `latest` | Mage version. Example: `v1.9.0` |
| `args` | String | | Arguments to pass to Mage |
| `workdir` | String | `.` | Working directory (below repository root) |

## Keep up-to-date with GitHub Dependabot
## Using on GHES

Since [Dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot)
has [native GitHub Actions support](https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates#package-ecosystem),
to enable it on your GitHub repo all you need to do is add the `.github/dependabot.yml` file:
If you specify a version or `latest` of GoReleaser in your workflow, the
version will be downloaded from [GitHub Releases in `magefile/mage`](https://github.com/magefile/mage/releases)
repository. These calls to `magefile/mage` are made via unauthenticated
requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).

If more requests are made within the time frame, then you will start to see
rate-limit errors during downloading that looks like:

```
##[error]API rate limit exceeded for...
```

To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new)
and pass it as the `github_token` input for the action:

```yaml
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
uses: magefile/mage-action@v2
with:
github_token: ${{ secrets.GH_DOTCOM_TOKEN }}
version: v1.14.0
```

If the runner is not able to access `github.com`, it will take the default one
available on the GitHub Runner or runner's tool cache. See "[Setting up the
tool cache on self-hosted runners without internet
access](https://docs.github.com/en/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
for more information.

## License

MIT. See `LICENSE` for more details.
10 changes: 8 additions & 2 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import * as github from '../src/github';

describe('github', () => {
it('returns latest Mage GitHub release', async () => {
const release = await github.getRelease('latest');
const release = await github.getLatestRelease(process.env.GITHUB_TOKEN || '');
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});

it('returns v1.8.0 Mage GitHub release', async () => {
const release = await github.getRelease('v1.8.0');
const release = await github.getReleaseTag('v1.8.0', process.env.GITHUB_TOKEN || '');
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v1.8.0');
});

it('unknown release', async () => {
await expect(github.getReleaseTag('foo', process.env.GITHUB_TOKEN || '')).rejects.toThrowError(
new Error('Cannot get release foo: HttpError: Not Found')
);
});
});
4 changes: 2 additions & 2 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import * as installer from '../src/installer';

describe('installer', () => {
it('acquires v1.8.0 version of Mage', async () => {
const mage = await installer.getMage('v1.8.0');
const mage = await installer.getMage('v1.8.0', process.env.GITHUB_TOKEN || '');
expect(fs.existsSync(mage)).toBe(true);
}, 100000);

it('acquires latest version of Mage', async () => {
const mage = await installer.getMage('latest');
const mage = await installer.getMage('latest', process.env.GITHUB_TOKEN || '');
expect(fs.existsSync(mage)).toBe(true);
}, 100000);
});
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ inputs:
workdir:
description: 'Working directory (below repository root)'
required: false
github_token:
# https://github.com/actions/setup-go/blob/21459d0b7b1d63741429b748885bf5a4974593b4/action.yml#L12-L14
description: >
Used to verifiy the Git tag exists on docker/buildx repo. Since there's a
default, this is typically not supplied by the user. When running this
action on github.com, the default value is sufficient. When running on
GHES, you can pass a personal access token for github.com if you are
experiencing rate limiting.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}

runs:
using: 'node16'
Expand Down
3 changes: 2 additions & 1 deletion dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run test --coverageDirectory=/tmp/coverage
--mount=type=secret,id=GITHUB_TOKEN \
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /
8 changes: 7 additions & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 67646e5

Please sign in to comment.