Skip to content

Commit

Permalink
Support subdirectory packages and alternate Registrator users (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
christopher-dG authored Jun 24, 2021
1 parent 7e1f31a commit 0396762
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Register Julia packages via GitHub Actions.

## Basic Usage

Create and push a file `.github/workflows/register.yml` with the following contents:

```yml
Expand All @@ -26,3 +28,32 @@ On that page, click "Run workflow", fill in your desired version, then click "Ru
Your Project.toml will be updated, and a comment triggering [Registrator](https://github.com/JuliaRegistries/Registrator.jl) will be made on the resulting commit.
You can also tell it to bump a version component rather than specifying the exact version.
To do this, use "major", "minor", or "patch" as the version input to perform the corresponding bump.
## Subdirectory Packages
To register packages in subdirectories, update your workflow file to the following:
```yml
on:
workflow_dispatch:
inputs:
version:
description: Version to register or component to bump
required: true
subdir:
description: Subdirectory containing the package to register
```
Then fill out the value when triggering the action.
For example, if your `Project.toml` is at `julia/Project.toml`, then give it the value `julia`.

## Private Registries

If you're using an alternate or private registry with the Registrator GitHub App set up on it, then update your workflow file to the following:

```yml
- uses: julia-actions/RegisterAction@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
registrator: MyBotUsername
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
token:
description: GitHub API token
required: true
registrator:
description: Registrator bot username
default: JuliaRegistrator
runs:
using: node12
main: register.js
Expand Down
20 changes: 12 additions & 8 deletions register.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const github = require("@actions/github");
const semver = require("semver");

const CLIENT = github.getOctokit(core.getInput("token", { required: true }));
const REGISTRATOR = core.getInput("registrator", { required: true });
const EVENT = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH));
const SUBDIR = EVENT.inputs.subdir;
const REPO = {
owner: process.env.GITHUB_REPOSITORY.split("/")[0],
repo: process.env.GITHUB_REPOSITORY.split("/")[1],
Expand Down Expand Up @@ -40,13 +42,15 @@ const resolveVersion = async () => {
return semver.inc(current, input);
};

const getProjectTomlPath = () => SUBDIR ? `${SUBDIR}/Project.toml` : "Project.toml";

const getProjectToml = async () => {
if (PROJECT_TOML) {
return PROJECT_TOML;
}
const content = await CLIENT.repos.getContent({
...REPO,
path: "Project.toml",
path: getProjectTomlPath(),
});
PROJECT_TOML = Buffer.from(content.data.content, "base64").toString();
return PROJECT_TOML;
Expand All @@ -67,7 +71,7 @@ const setVersion = async version => {
const branch = process.env.GITHUB_REF.substr(11) // Remove 'refs/heads/'.
return CLIENT.repos.createOrUpdateFileContents({
...REPO,
path: "Project.toml",
path: getProjectTomlPath(),
message: `Set version to ${version}`,
content: Buffer.from(updated).toString("base64"),
sha: blobSha(project),
Expand All @@ -81,12 +85,12 @@ const blobSha = contents => {
return hash.digest("hex");
};

const triggerRegistrator = sha => {
return CLIENT.repos.createCommitComment({
...REPO,
commit_sha: sha,
body: "@JuliaRegistrator register",
});
const triggerRegistrator = commit_sha => {
let body = `@${REGISTRATOR} register`;
if (SUBDIR) {
body += ` subdir=${SUBDIR}`;
}
return CLIENT.repos.createCommitComment({ ...REPO, commit_sha, body });
};

if (!module.parent) {
Expand Down

0 comments on commit 0396762

Please sign in to comment.