Skip to content

Commit

Permalink
v1.1.0 - Add support for private repos (#9)
Browse files Browse the repository at this point in the history
* Discontinue "latest" tag

* Add token for private repos

* [auto] Update compiled version

* Bump version in docs
  • Loading branch information
EndBug authored Oct 22, 2019
1 parent bab6013 commit f91627f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 30 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/latest.yml

This file was deleted.

10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ You have to set up a step like this in your workflow (this assumes you've alread
```yaml
- name: Check if version has been updated # You can edit this
id: check # This will be the reference for getting the outputs
uses: EndBug/version-check@v1.0.1 # You can choose teh version/branch you prefer
uses: EndBug/version-check@v1.1.0 # You can choose the version/branch you prefer
with: # You can find more info about inputs below
file-name: package.json
diff-search: true
file-name: package.json
token: ${{ secrets.GITHUB_TOKEN }}
```
### Inputs
- `file-name` (optional) : you can use this to indicate a custom path to your `package.json`; if you keep your package file in the root directory (as every normal person would do) you can omit this.
- `diff-search` (optional) : whether to search in every commit's diff. This is useful if you often do change the version manually without including it in the title: you can find more info on how the action detects the version change [here](doc/logic_chain.md). If you only use `npm version` to bump versions then you can omit this.
- `file-name` (optional) : you can use this to indicate a custom path to your `package.json`; if you keep your package file in the root directory (as every normal person would do) you can omit this.
- `token` (optional) : you can put your bearer GitHub token here. This is needed only when running the action on private repostiories, if you're running it on a public repo you can omit this. If you need to set this, you can use the built-in `GITHUB_TOKEN` secret that GitHub generates for your repo's actions: you cna find more info about it [here](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#github_token-secret).

### Outputs

Expand All @@ -37,7 +39,7 @@ Here's an example:
```yaml
- name: Check if version has been updated
id: check
uses: EndBug/version-check@v1.0.1
uses: EndBug/version-check@v1.1.0
- name: Log when changed
if: steps.check.outputs.changed == 'true'
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
file-name:
description: A custom path to the package.json file
required: false
token:
description: A GitHub token to use when running on private repos
required: false

outputs:
changed:
Expand All @@ -22,4 +25,4 @@ runs:

branding:
icon: package
color: green
color: green
4 changes: 2 additions & 2 deletions doc/auto-publish-walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ publish:
```

## 2. Detecting a version change
I didn't find a good way to do that so I made another action, [`version-check`][3]: this action scans the commits of every push and tries to figure out whether they include a version change.
I didn't find a good way to do that so I made another action, [`version-check`][3]: this action scans the commits of every push and tries to figure out whether they include a version change. Remeber to set eventual needed arguments/inputs!
You need to set up these two steps:

```yml
Expand Down Expand Up @@ -146,7 +146,7 @@ fs.writeFileSync(join(__dirname, '../package.json'), JSON.stringify(pkg))
uses: actions/setup-node@v1.2.0
with:
registry-url: 'https://npm.pkg.github.com/'
scope: '@endbug'
scope: '@yourscope'
- name: Set up the package for GPR
if: steps.check.outputs.changed == 'true'
Expand Down
7 changes: 5 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const fs_1 = require("fs");
const path_1 = require("path");
const semver_diff_1 = __importDefault(require("semver-diff"));
const semver_regex_1 = __importDefault(require("semver-regex"));
const packageFileName = core.getInput('file-name') || 'package.json', dir = process.env.GITHUB_WORKSPACE || '/github/workspace', eventFile = process.env.GITHUB_EVENT_PATH || '/github/workflow/event.json';
const packageFileName = core.getInput('file-name') || 'package.json', dir = process.env.GITHUB_WORKSPACE || '/github/workspace', eventFile = process.env.GITHUB_EVENT_PATH || '/github/workflow/event.json', token = core.getInput('token');
function main() {
return __awaiter(this, void 0, void 0, function* () {
const eventObj = yield readJson(eventFile);
Expand All @@ -38,7 +38,10 @@ function isPackageObj(value) {
function getCommit(sha) {
return __awaiter(this, void 0, void 0, function* () {
let url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`;
return (yield axios_1.default.get(url)).data;
let headers = token ? {
Authorization: `Bearer ${token}`
} : undefined;
return (yield axios_1.default.get(url, { headers })).data;
});
}
function checkCommits(commits, version) {
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import semverRegex from 'semver-regex';

const packageFileName = core.getInput('file-name') || 'package.json',
dir = process.env.GITHUB_WORKSPACE || '/github/workspace',
eventFile = process.env.GITHUB_EVENT_PATH || '/github/workflow/event.json'
eventFile = process.env.GITHUB_EVENT_PATH || '/github/workflow/event.json',
token = core.getInput('token')

type ArgValue<T> =
T extends 'changed' ? boolean :
Expand Down Expand Up @@ -39,7 +40,10 @@ function isPackageObj(value): value is PackageObj {

async function getCommit(sha: string): Promise<CommitReponse> {
let url = `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/commits/${sha}`
return (await axios.get(url)).data
let headers = token ? {
Authorization: `Bearer ${token}`
} : undefined
return (await axios.get(url, { headers })).data
}
interface CommitReponse {
url: string
Expand Down Expand Up @@ -264,4 +268,4 @@ if (require.main == module) {
console.error(e.message || e)
}
})
}
}

0 comments on commit f91627f

Please sign in to comment.