Skip to content

Commit

Permalink
feat!: add optional license field (#9)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The action will now fail if the license cannot be
determined using the GitHub API and the `license` field is not set.
  • Loading branch information
mrcjkb authored Feb 10, 2023
1 parent 0c8c3ca commit d19a2a9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v2.0.0] - 2023-02-10
### Added
- Optional `license` input.
### Changed
- BREAKING: The action will fail if no `license` input is set and GitHub cannot determine the license automatically.

## [v1.0.2] - 2023-02-06
### Fixed
- Escape quotes in summary
Expand Down
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
env:
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
```
Expand All @@ -57,7 +57,7 @@ Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
dependencies: |
plenary.nvim
Expand All @@ -73,7 +73,7 @@ Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
labels: |
neovim
Expand All @@ -87,7 +87,7 @@ Example to specify additional directories:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
copy_directories: |
doc
Expand All @@ -111,7 +111,7 @@ Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
detailed_description: |
Publishes packages to LuaRocks when a git tag is pushed.
Expand All @@ -130,7 +130,7 @@ Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
build_type: "make"
```
Expand All @@ -146,11 +146,31 @@ Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
template: "/path/to/my/template.rockspec"
```

### `license` (optional)

The license used by this package.
If not set (by default), this workflow will fetch the license SPDX ID from GitHub.
If GitHub cannot detect the license automatically, you can set it here.

Example:

```yaml
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v2.0.0
with:
license: "MIT"
```
> **Note**
>
> If GitHub can detect the license automatically, it will be displayed in your repository's About section.
>
> ![about](https://user-images.githubusercontent.com/12857160/218101570-b0605716-0457-47c1-ab2e-91d48a48881c.png)

## Limitations

* This workflow only works on public repositories.
Expand Down
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ inputs:
description: "Path to a rockspec template."
required: true
default: "/rockspec.template"
license:
description: |
The license SPDX identifier.
By default, it will be fetched from GitHub.
But sometimes, GitHub does not recognise it,
in which case LuaRocks will fall back to this one.
required: false
runs:
using: "docker"
image: "Dockerfile"
Expand All @@ -54,3 +61,4 @@ runs:
- ${{ inputs.detailed_description }}
- ${{ inputs.build_type }}
- ${{ inputs.template }}
- ${{ inputs.license }}
17 changes: 15 additions & 2 deletions bin/luarocks-tag-release.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
---@field detailed_description_lines string[]
---@field build_type string
---@field rockspec_template_file_path string
---@field license string|nil

---@type string[]
local arg_list = { ... }
Expand Down Expand Up @@ -61,6 +62,7 @@ local args = {
detailed_description_lines = parse_list_args(arg_list[6]),
build_type = arg_list[7],
rockspec_template_file_path = arg_list[8],
license = #arg_list > 8 and arg_list[9] ~= '' and arg_list[9] or nil,
}
table.insert(args.dependencies, 1, 'lua >= 5.1')

Expand Down Expand Up @@ -146,13 +148,24 @@ local content = rockspec_template_file:read('*a')
rockspec_template_file:close()
local repo_url = github_server_url .. '/' .. github_repo
local homepage = repo_url
local license = ''
local license
local repo_info_str, _ =
execute('curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/' .. github_repo, print)
if repo_info_str and repo_info_str ~= '' then
local json = require('dkjson')
local repo_meta = json.decode(repo_info_str)
license = repo_meta.license and "license = '" .. repo_meta.license.spdx_id .. "'" or ''
local repo_license = repo_meta.license
if args.license then
license = "license = '" .. args.license .. "'"
elseif repo_license and repo_license.spdx_id ~= '' and repo_license.spdx_id ~= 'NOASSERTION' then
license = "license = '" .. repo_license.spdx_id .. "'"
else
error([[
Could not get the license SPDX ID from the GitHub API.
Please add a license file that GitHub can recognise or add a `license` input.
See: https://github.com/nvim-neorocks/luarocks-tag-release#license
]])
end
if not args.summary or args.summary == '' then
args.summary = repo_meta.description and repo_meta.description or ''
end
Expand Down

0 comments on commit d19a2a9

Please sign in to comment.