mirror of
https://github.com/goreleaser/goreleaser-action
synced 2026-08-29 20:38:27 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b953231f81 | ||
|
|
c127c9be61 | ||
|
|
affd781166 | ||
|
|
39419c3fac | ||
|
|
a80c8fd82d | ||
|
|
79d4afbba1 | ||
|
|
5df302e5e9 | ||
|
|
69b075db94 | ||
|
|
13b378d620 | ||
|
|
cb1d514d21 | ||
|
|
2efe451c4b | ||
|
|
fcc88bd028 | ||
|
|
25383ef1e0 | ||
|
|
bc087ef4b9 | ||
|
|
f9141d00ae | ||
|
|
1bdedc7bba | ||
|
|
5a54d7e660 | ||
|
|
a59bcd6856 | ||
|
|
b59bff5dc3 | ||
|
|
b2263bd81e | ||
|
|
76bde1890b | ||
|
|
194deb5974 | ||
|
|
ac067437f5 | ||
|
|
bbb1d19f5b | ||
|
|
d0c4a003d3 | ||
|
|
c2b33cd784 | ||
|
|
35d40269d0 | ||
|
|
be642f174c | ||
|
|
d401a5332a | ||
|
|
70eb4e573c | ||
|
|
a3b2f49e7c | ||
|
|
8571fa911c | ||
|
|
a604a9b2f7 | ||
|
|
239f064349 | ||
|
|
ab4f17620b | ||
|
|
15c488ce8f | ||
|
|
f08023819a | ||
|
|
4921ce3062 | ||
|
|
6b584eeb7a | ||
|
|
5e15885530 | ||
|
|
748d6973af | ||
|
|
0e0aa65c79 | ||
|
|
b458824747 | ||
|
|
d8a076a057 | ||
|
|
e1c89b9548 | ||
|
|
e64074c2ea | ||
|
|
edea00d0c6 | ||
|
|
56f5b77f7f | ||
|
|
c1dfc73b78 | ||
|
|
97d4c6b042 | ||
|
|
0e7950faac | ||
|
|
09ce14113d | ||
|
|
50de962f84 | ||
|
|
a61bc075fd | ||
|
|
d19982d4d2 | ||
|
|
499c61b7c5 | ||
|
|
ddc7bc8b43 | ||
|
|
9c48726d5e | ||
|
|
d0f90f55ae | ||
|
|
f2a4c95ec7 | ||
|
|
3d57a20621 | ||
|
|
3f5ecc4e17 | ||
|
|
70364181ef | ||
|
|
7007251a74 | ||
|
|
c5a3850c06 | ||
|
|
4441f834e5 | ||
|
|
e8c391b2a4 | ||
|
|
608bdefa0e |
@@ -0,0 +1,2 @@
|
||||
/coverage
|
||||
/node_modules
|
||||
+3
-2
@@ -1,2 +1,3 @@
|
||||
github: crazy-max
|
||||
custom: https://www.paypal.me/crazyws
|
||||
github: [crazy-max, caarlos0]
|
||||
open_collective: goreleaser
|
||||
custom: ["https://goreleaser.com/pro"]
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 12 KiB |
+117
-13
@@ -3,14 +3,16 @@ name: ci
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 10 * * *' # everyday at 10am
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- releases/v*
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- releases/v*
|
||||
- 'master'
|
||||
- 'releases/v*'
|
||||
tags:
|
||||
- 'v*'
|
||||
pull_request:
|
||||
branches:
|
||||
- 'master'
|
||||
- 'releases/v*'
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
@@ -24,33 +26,79 @@ jobs:
|
||||
- windows-latest
|
||||
version:
|
||||
- latest
|
||||
- v0.117.0
|
||||
- '~> 0.182'
|
||||
distribution:
|
||||
- goreleaser
|
||||
- goreleaser-pro
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Check
|
||||
uses: ./
|
||||
with:
|
||||
version: ${{ matrix.version }}
|
||||
args: check --debug
|
||||
workdir: ./test
|
||||
-
|
||||
name: GoReleaser
|
||||
if: ${{ !(github.event_name == 'pull_request' && matrix.distribution == 'goreleaser-pro') }}
|
||||
uses: ./
|
||||
env:
|
||||
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
version: ${{ matrix.version }}
|
||||
args: release --skip-publish --rm-dist
|
||||
workdir: ./test
|
||||
|
||||
install-only:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
version:
|
||||
- latest
|
||||
- '~> 0.166'
|
||||
distribution:
|
||||
- goreleaser
|
||||
- goreleaser-pro
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: GoReleaser
|
||||
if: ${{ !(github.event_name == 'pull_request' && matrix.distribution == 'goreleaser-pro') }}
|
||||
uses: ./
|
||||
with:
|
||||
distribution: ${{ matrix.distribution }}
|
||||
version: ${{ matrix.version }}
|
||||
install-only: true
|
||||
-
|
||||
name: Check
|
||||
if: ${{ !(github.event_name == 'pull_request' && matrix.distribution == 'goreleaser-pro') }}
|
||||
run: |
|
||||
goreleaser check --debug
|
||||
|
||||
signing:
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: github.event_name != 'pull_request'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
@@ -61,20 +109,20 @@ jobs:
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Import GPG key
|
||||
id: import_gpg
|
||||
uses: crazy-max/ghaction-import-gpg@v3
|
||||
uses: crazy-max/ghaction-import-gpg@v4
|
||||
with:
|
||||
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY_TEST }}
|
||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY_TEST }}
|
||||
passphrase: ${{ secrets.PASSPHRASE_TEST }}
|
||||
-
|
||||
name: Check
|
||||
@@ -82,6 +130,7 @@ jobs:
|
||||
with:
|
||||
version: latest
|
||||
args: -f .goreleaser-signing.yml check --debug
|
||||
workdir: ./test
|
||||
env:
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
-
|
||||
@@ -90,5 +139,60 @@ jobs:
|
||||
with:
|
||||
version: latest
|
||||
args: -f .goreleaser-signing.yml release --skip-publish --rm-dist
|
||||
workdir: ./test
|
||||
env:
|
||||
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
|
||||
|
||||
upload-artifact:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Check
|
||||
uses: ./
|
||||
with:
|
||||
args: check --debug
|
||||
workdir: ./test
|
||||
-
|
||||
name: GoReleaser
|
||||
uses: ./
|
||||
with:
|
||||
args: release --skip-publish --rm-dist
|
||||
workdir: ./test
|
||||
-
|
||||
name: Upload assets
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: myapp
|
||||
path: ./test/dist/*
|
||||
|
||||
current-tag:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: GoReleaser
|
||||
uses: ./
|
||||
with:
|
||||
args: release --skip-publish --rm-dist
|
||||
workdir: ./test
|
||||
env:
|
||||
GORELEASER_CURRENT_TAG: v1.2.3
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
name: pre-checkin
|
||||
|
||||
on:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
jobs:
|
||||
pre-checkin:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
-
|
||||
name: Install
|
||||
run: yarn install
|
||||
-
|
||||
name: Pre-checkin
|
||||
run: yarn run pre-checkin
|
||||
-
|
||||
name: Check for uncommitted changes
|
||||
run: |
|
||||
if [[ `git status --porcelain` ]]; then
|
||||
git status --porcelain
|
||||
echo "::warning::Found changes. Please run 'yarn run pre-checkin' and push"
|
||||
fi
|
||||
+15
-21
@@ -3,40 +3,34 @@ name: test
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- releases/v*
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- 'master'
|
||||
- 'releases/v*'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
branches:
|
||||
- 'master'
|
||||
- 'releases/v*'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macOS-latest
|
||||
- windows-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2.3.3
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Install
|
||||
run: yarn install
|
||||
name: Validate
|
||||
uses: docker/bake-action@v1
|
||||
with:
|
||||
targets: validate
|
||||
-
|
||||
name: Test
|
||||
run: yarn run test
|
||||
uses: docker/bake-action@v1
|
||||
with:
|
||||
targets: test
|
||||
-
|
||||
name: Upload coverage
|
||||
uses: codecov/codecov-action@v1.0.13
|
||||
if: success()
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
file: ./coverage/clover.xml
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## 2.2.1 (2020/10/01)
|
||||
|
||||
* Fix CVE-2020-15228
|
||||
|
||||
## 2.2.0 (2020/08/27)
|
||||
|
||||
* Use GITHUB_REF to retrieve tag before checking the most recent tag (#238)
|
||||
* Update deps
|
||||
|
||||
## 2.1.1 (2020/06/24)
|
||||
|
||||
* Fix workdir (#224)
|
||||
|
||||
## 2.1.0 (2020/06/15)
|
||||
|
||||
* Implement (optional) semver parsing of version (#213)
|
||||
* Remove unshallow step (goreleaser/goreleaser#1608)
|
||||
|
||||
## 2.0.2 (2020/05/10)
|
||||
|
||||
* Use template in `sign.args`
|
||||
|
||||
## 2.0.1 (2020/05/10)
|
||||
|
||||
* Dummy release to mark v2 as latest on the marketplace
|
||||
|
||||
## 2.0.0 (2020/05/10)
|
||||
|
||||
* Remove `key` input and use [Import GPG](https://github.com/crazy-max/ghaction-import-gpg) GitHub Action instead.
|
||||
* Make `args` input as required
|
||||
* Go 1.14
|
||||
* Update deps
|
||||
|
||||
## 1.5.1 (2020/05/10)
|
||||
|
||||
* Mark `key` input as deprecated
|
||||
|
||||
## 1.5.0 (2020/05/07)
|
||||
|
||||
* Use native GitHub Action tools to download assets and use GitHub API
|
||||
* Fix unexpected output when tag not found
|
||||
* Use GitHub Action exec
|
||||
* Cleanup local paths from extra fields
|
||||
* Add notes about limitation with GITHUB_TOKEN (#58)
|
||||
* Add Codecov
|
||||
|
||||
## 1.4.0 (2020/04/09)
|
||||
|
||||
* Use ncc and clean workflows
|
||||
* Update deps
|
||||
|
||||
## 1.3.1 (2020/02/14)
|
||||
|
||||
* Don't fail on `getTag` (#98)
|
||||
|
||||
## 1.3.0 (2020/02/11)
|
||||
|
||||
* Improve git tag detection (#77)
|
||||
* Only handle snapshot flag for release cmd (#94)
|
||||
* Use `core.info` instead of `console.log`
|
||||
* Update deps
|
||||
* Update gitattributes
|
||||
|
||||
## 1.2.1 (2020/01/20)
|
||||
|
||||
* Update deps
|
||||
|
||||
## 1.2.0 (2019/12/24)
|
||||
|
||||
* Update deps
|
||||
|
||||
## 1.1.0 (2019/12/02)
|
||||
|
||||
* Add input to run GoReleaser from a subdirectory (#45)
|
||||
|
||||
## 1.0.2 (2019/11/14)
|
||||
|
||||
* Fix tsc gen
|
||||
|
||||
## 1.0.1 (2019/11/14)
|
||||
|
||||
* Update deps
|
||||
|
||||
## 1.0.0 (2019/10/04)
|
||||
|
||||
* Stable release
|
||||
* Update deps
|
||||
|
||||
## 0.4.0 (2019/09/28)
|
||||
|
||||
* Move repository to GoReleaser org (#3)
|
||||
|
||||
## 0.3.0 (2019/09/26)
|
||||
|
||||
* Artifact signing (#2)
|
||||
|
||||
## 0.2.1 (2019/09/22)
|
||||
|
||||
* Typo
|
||||
|
||||
## 0.2.0 (2019/09/20)
|
||||
|
||||
* Snapshot forced if no tag found
|
||||
|
||||
## 0.1.0 (2019/09/20)
|
||||
|
||||
* Initial version
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019-2020 CrazyMax
|
||||
Copyright (c) 2019-2022 CrazyMax
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<a href="https://github.com/marketplace/actions/goreleaser-action"><img alt="GitHub marketplace" src="https://img.shields.io/badge/marketplace-goreleaser--action-blue?logo=github&style=flat-square"></a>
|
||||
<a href="https://github.com/goreleaser/goreleaser-action/actions?workflow=test"><img alt="Test workflow" src="https://img.shields.io/github/workflow/status/goreleaser/goreleaser-action/test?label=test&logo=github&style=flat-square"></a>
|
||||
<a href="https://codecov.io/gh/goreleaser/goreleaser-action"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/goreleaser/goreleaser-action?logo=codecov&style=flat-square"></a>
|
||||
<a href="https://github.com/sponsors/crazy-max"><img src="https://img.shields.io/badge/sponsor-crazy--max-181717.svg?logo=github&style=flat-square" alt="Become a sponsor"></a>
|
||||
</p>
|
||||
</p>
|
||||
|
||||
@@ -19,10 +18,14 @@ ___
|
||||
* [Workflow](#workflow)
|
||||
* [Run on new tag](#run-on-new-tag)
|
||||
* [Signing](#signing)
|
||||
* [Upload artifacts](#upload-artifacts)
|
||||
* [Install Only](#install-only)
|
||||
* [Customizing](#customizing)
|
||||
* [inputs](#inputs)
|
||||
* [outputs](#outputs)
|
||||
* [environment variables](#environment-variables)
|
||||
* [Limitation](#limitation)
|
||||
* [Development](#development)
|
||||
* [License](#license)
|
||||
|
||||
## Usage
|
||||
@@ -48,16 +51,18 @@ jobs:
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.14
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
```
|
||||
|
||||
> **IMPORTANT**: note the `fetch-depth: 0` input in `Checkout` step. It is required for the changelog to work correctly.
|
||||
@@ -91,15 +96,16 @@ Or with a condition on GoReleaser step:
|
||||
|
||||
### Signing
|
||||
|
||||
If [signing is enabled](https://goreleaser.com/customization/#Signing) in your GoReleaser configuration, you can use the [Import GPG](https://github.com/crazy-max/ghaction-import-gpg) GitHub Action along with this one:
|
||||
If [signing is enabled](https://goreleaser.com/customization/#Signing) in your GoReleaser configuration, you can use
|
||||
the [Import GPG](https://github.com/crazy-max/ghaction-import-gpg) GitHub Action along with this one:
|
||||
|
||||
```yaml
|
||||
-
|
||||
name: Import GPG key
|
||||
id: import_gpg
|
||||
uses: crazy-max/ghaction-import-gpg@v3
|
||||
uses: crazy-max/ghaction-import-gpg@v4
|
||||
with:
|
||||
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
|
||||
passphrase: ${{ secrets.PASSPHRASE }}
|
||||
-
|
||||
name: Run GoReleaser
|
||||
@@ -120,35 +126,83 @@ signs:
|
||||
args: ["--batch", "-u", "{{ .Env.GPG_FINGERPRINT }}", "--output", "${signature}", "--detach-sign", "${artifact}"]
|
||||
```
|
||||
|
||||
### Upload artifacts
|
||||
|
||||
For some events like pull request or schedule you might want to store the artifacts somewhere for testing
|
||||
purpose. You can do that with the [actions/upload-artifact](https://github.com/actions/upload-artifact) action:
|
||||
|
||||
```yaml
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
-
|
||||
name: Upload assets
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: myapp
|
||||
path: dist/*
|
||||
```
|
||||
|
||||
### Install Only
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
-
|
||||
name: Install GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
install-only: true
|
||||
-
|
||||
name: Show GoReleaser version
|
||||
run: goreleaser -v
|
||||
```
|
||||
|
||||
## Customizing
|
||||
|
||||
### inputs
|
||||
|
||||
Following inputs can be used as `step.with` keys
|
||||
|
||||
| Name | Type | Default | Description |
|
||||
|------------------|---------|-----------|-------------------------------------------|
|
||||
| `version`**¹** | String | `latest` | GoReleaser version |
|
||||
| `args` | String | | Arguments to pass to GoReleaser |
|
||||
| `workdir` | String | `.` | Working directory (below repository root) |
|
||||
| Name | Type | Default | Description |
|
||||
|------------------|---------|--------------|------------------------------------------------------------------|
|
||||
| `distribution` | String | `goreleaser` | GoReleaser distribution, either `goreleaser` or `goreleaser-pro` |
|
||||
| `version`**¹** | String | `latest` | GoReleaser version |
|
||||
| `args` | String | | Arguments to pass to GoReleaser |
|
||||
| `workdir` | String | `.` | Working directory (below repository root) |
|
||||
| `install-only` | Bool | `false` | Just install GoReleaser |
|
||||
|
||||
> **¹** Can be a fixed version like `v0.117.0` or a max satisfying semver one like `~> 0.132`. In this case this will return `v0.132.1`.
|
||||
|
||||
### outputs
|
||||
|
||||
Following outputs are available
|
||||
|
||||
| Name | Type | Description |
|
||||
|-------------------|---------|---------------------------------------|
|
||||
| `artifacts` | JSON | Build result artifacts |
|
||||
| `metadata` | JSON | Build result metadata |
|
||||
|
||||
### environment variables
|
||||
|
||||
Following environment variables can be used as `step.env` keys
|
||||
|
||||
| Name | Description |
|
||||
|----------------|---------------------------------------|
|
||||
| `GITHUB_TOKEN` | [GITHUB_TOKEN](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
|
||||
| Name | Description |
|
||||
|------------------|---------------------------------------|
|
||||
| `GITHUB_TOKEN` | [GITHUB_TOKEN](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
|
||||
| `GORELEASER_KEY` | Your [GoReleaser Pro](https://goreleaser.com/pro) License Key, in case you are using the `goreleaser-pro` distribution |
|
||||
|
||||
## Limitation
|
||||
|
||||
`GITHUB_TOKEN` permissions [are limited to the repository](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret)
|
||||
that contains your workflow.
|
||||
that contains your workflow.
|
||||
|
||||
If you need to push the homebrew tap to another repository, you must therefore create a custom [Personal Access Token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/)
|
||||
with `repo` permissions and [add it as a secret in the repository](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets). If you create a
|
||||
with `repo` permissions and [add it as a secret in the repository](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets). If you create a
|
||||
secret named `GH_PAT`, the step will look like this:
|
||||
|
||||
```yaml
|
||||
@@ -162,6 +216,19 @@ secret named `GH_PAT`, the step will look like this:
|
||||
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```
|
||||
# format code and build javascript artifacts
|
||||
docker buildx bake pre-checkin
|
||||
|
||||
# validate all code has correctly formatted and built
|
||||
docker buildx bake validate
|
||||
|
||||
# run tests
|
||||
docker buildx bake test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT. See `LICENSE` for more details.
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import * as os from 'os';
|
||||
import * as context from '../src/context';
|
||||
|
||||
describe('setOutput', () => {
|
||||
beforeEach(() => {
|
||||
process.stdout.write = jest.fn();
|
||||
});
|
||||
|
||||
it('setOutput produces the correct command', () => {
|
||||
context.setOutput('some output', 'some value');
|
||||
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
|
||||
});
|
||||
|
||||
it('setOutput handles bools', () => {
|
||||
context.setOutput('some output', false);
|
||||
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
|
||||
});
|
||||
|
||||
it('setOutput handles numbers', () => {
|
||||
context.setOutput('some output', 1.01);
|
||||
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
|
||||
});
|
||||
});
|
||||
|
||||
// Assert that process.stdout.write calls called only with the given arguments.
|
||||
function assertWriteCalls(calls: string[]): void {
|
||||
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length);
|
||||
for (let i = 0; i < calls.length; i++) {
|
||||
expect(process.stdout.write).toHaveBeenNthCalledWith(i + 1, calls[i]);
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ describe('git', () => {
|
||||
expect(tag).not.toEqual('');
|
||||
});
|
||||
it('returns git tag through GITHUB_SHA', async () => {
|
||||
process.env.GITHUB_SHA = '6e37040623d14330555c7be1603a9182cf92d32a';
|
||||
process.env.GITHUB_SHA = '6389ff5bd287fd6948a7ccda8af8da4f0bbc856a';
|
||||
const tag: string = await git.getTag();
|
||||
console.log(`tag: ${tag}`);
|
||||
expect(tag).toEqual('v1');
|
||||
expect(tag).toEqual('v2.2.1');
|
||||
});
|
||||
it('returns git tag through GITHUB_REF', async () => {
|
||||
process.env.GITHUB_REF = 'refs/tags/v2.2.1';
|
||||
|
||||
@@ -2,19 +2,33 @@ import * as github from '../src/github';
|
||||
|
||||
describe('github', () => {
|
||||
it('returns latest GoReleaser GitHub release', async () => {
|
||||
const release = await github.getRelease('latest');
|
||||
const release = await github.getRelease('goreleaser', 'latest');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).not.toEqual('');
|
||||
console.log(`tag_name: ${release?.tag_name}`);
|
||||
});
|
||||
it('returns v0.117.0 GoReleaser GitHub release', async () => {
|
||||
const release = await github.getRelease('v0.117.0');
|
||||
it('returns v0.182.0 GoReleaser GitHub release', async () => {
|
||||
const release = await github.getRelease('goreleaser', 'v0.182.0');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).toEqual('v0.117.0');
|
||||
expect(release?.tag_name).toEqual('v0.182.0');
|
||||
});
|
||||
it('returns v0.132.1 GoReleaser GitHub release', async () => {
|
||||
const release = await github.getRelease('~> 0.132');
|
||||
it('returns v0.182.1 GoReleaser GitHub release', async () => {
|
||||
const release = await github.getRelease('goreleaser', '~> 0.182');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).toEqual('v0.132.1');
|
||||
expect(release?.tag_name).toEqual('v0.182.1');
|
||||
});
|
||||
it('returns latest GoReleaser Pro GitHub release', async () => {
|
||||
const release = await github.getRelease('goreleaser-pro', 'latest');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).not.toEqual('');
|
||||
});
|
||||
it('returns v0.182.0-pro GoReleaser Pro GitHub release', async () => {
|
||||
const release = await github.getRelease('goreleaser-pro', 'v0.182.0-pro');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).toEqual('v0.182.0-pro');
|
||||
});
|
||||
it('returns v0.182.1-pro GoReleaser Pro GitHub release when using semver', async () => {
|
||||
const release = await github.getRelease('goreleaser-pro', '~> 0.182');
|
||||
expect(release).not.toBeNull();
|
||||
expect(release?.tag_name).toEqual('v0.182.1-pro');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import * as fs from 'fs';
|
||||
import * as goreleaser from '../src/goreleaser';
|
||||
|
||||
describe('install', () => {
|
||||
it('acquires v0.182.0 version of GoReleaser', async () => {
|
||||
const bin = await goreleaser.install('goreleaser', 'v0.182.0');
|
||||
expect(fs.existsSync(bin)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires latest version of GoReleaser', async () => {
|
||||
const bin = await goreleaser.install('goreleaser', 'latest');
|
||||
expect(fs.existsSync(bin)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires v0.182.0-pro version of GoReleaser Pro', async () => {
|
||||
const bin = await goreleaser.install('goreleaser-pro', 'v0.182.0-pro');
|
||||
expect(fs.existsSync(bin)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires latest version of GoReleaser Pro', async () => {
|
||||
const bin = await goreleaser.install('goreleaser-pro', 'latest');
|
||||
expect(fs.existsSync(bin)).toBe(true);
|
||||
}, 100000);
|
||||
});
|
||||
|
||||
describe('distribSuffix', () => {
|
||||
it('suffixes pro distribution', async () => {
|
||||
expect(goreleaser.distribSuffix('goreleaser-pro')).toEqual('-pro');
|
||||
});
|
||||
it('does not suffix oss distribution', async () => {
|
||||
expect(goreleaser.distribSuffix('goreleaser')).toEqual('');
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import fs = require('fs');
|
||||
import * as installer from '../src/installer';
|
||||
|
||||
describe('installer', () => {
|
||||
it('acquires v0.117.0 version of GoReleaser', async () => {
|
||||
const goreleaser = await installer.getGoReleaser('v0.117.0');
|
||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
||||
}, 100000);
|
||||
|
||||
it('acquires latest version of GoReleaser', async () => {
|
||||
const goreleaser = await installer.getGoReleaser('latest');
|
||||
expect(fs.existsSync(goreleaser)).toBe(true);
|
||||
}, 100000);
|
||||
});
|
||||
+16
-2
@@ -1,23 +1,37 @@
|
||||
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
|
||||
name: 'GoReleaser Action'
|
||||
description: 'GitHub Action for GoReleaser, a release automation tool for Go projects'
|
||||
author: 'crazy-max'
|
||||
author: 'goreleaser'
|
||||
branding:
|
||||
color: 'green'
|
||||
icon: 'package'
|
||||
|
||||
inputs:
|
||||
distribution:
|
||||
description: 'GoReleaser Distribution (goreleaser or goreleaser-pro)'
|
||||
default: 'goreleaser'
|
||||
required: false
|
||||
version:
|
||||
description: 'GoReleaser version'
|
||||
default: 'latest'
|
||||
required: false
|
||||
args:
|
||||
description: 'Arguments to pass to GoReleaser'
|
||||
required: true
|
||||
required: false
|
||||
workdir:
|
||||
description: 'Working directory (below repository root)'
|
||||
default: '.'
|
||||
required: false
|
||||
install-only:
|
||||
description: 'Just install GoReleaser'
|
||||
default: 'false'
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
artifacts:
|
||||
description: 'Build result artifacts'
|
||||
metadata:
|
||||
description: 'Build result metadata'
|
||||
|
||||
runs:
|
||||
using: 'node12'
|
||||
|
||||
+8820
-1908
File diff suppressed because one or more lines are too long
@@ -0,0 +1,67 @@
|
||||
variable "NODE_VERSION" {
|
||||
default = "12"
|
||||
}
|
||||
|
||||
target "node-version" {
|
||||
args = {
|
||||
NODE_VERSION = NODE_VERSION
|
||||
}
|
||||
}
|
||||
|
||||
group "default" {
|
||||
targets = ["build"]
|
||||
}
|
||||
|
||||
group "pre-checkin" {
|
||||
targets = ["vendor-update", "format", "build"]
|
||||
}
|
||||
|
||||
group "validate" {
|
||||
targets = ["format-validate", "build-validate", "vendor-validate"]
|
||||
}
|
||||
|
||||
target "build" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "build-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "build-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "build-validate"
|
||||
}
|
||||
|
||||
target "format" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "format-update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "format-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/build.Dockerfile"
|
||||
target = "format-validate"
|
||||
}
|
||||
|
||||
target "vendor-update" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "update"
|
||||
output = ["."]
|
||||
}
|
||||
|
||||
target "vendor-validate" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/vendor.Dockerfile"
|
||||
target = "validate"
|
||||
}
|
||||
|
||||
target "test" {
|
||||
inherits = ["node-version"]
|
||||
dockerfile = "./hack/test.Dockerfile"
|
||||
target = "test-coverage"
|
||||
output = ["./coverage"]
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache cpio findutils git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS deps
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install
|
||||
|
||||
FROM deps AS build
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run build && mkdir /out && cp -Rf dist /out/
|
||||
|
||||
FROM scratch AS build-update
|
||||
COPY --from=build /out /
|
||||
|
||||
FROM build AS build-validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
git add -A && cp -rf /out/* .; \
|
||||
if [ -n "$(git status --porcelain -- dist)" ]; then \
|
||||
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'; \
|
||||
git status --porcelain -- dist; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
FROM deps AS format
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format \
|
||||
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' | cpio -pdm /out
|
||||
|
||||
FROM scratch AS format-update
|
||||
COPY --from=format /out /
|
||||
|
||||
FROM deps AS format-validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn run format-check \
|
||||
@@ -0,0 +1,21 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS deps
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install
|
||||
|
||||
FROM deps AS test
|
||||
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
|
||||
|
||||
FROM scratch AS test-coverage
|
||||
COPY --from=test /tmp/coverage /
|
||||
@@ -0,0 +1,23 @@
|
||||
# syntax=docker/dockerfile:1.2
|
||||
ARG NODE_VERSION
|
||||
|
||||
FROM node:${NODE_VERSION}-alpine AS base
|
||||
RUN apk add --no-cache git
|
||||
WORKDIR /src
|
||||
|
||||
FROM base AS vendored
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
--mount=type=cache,target=/src/node_modules \
|
||||
yarn install && mkdir /out && cp yarn.lock /out
|
||||
|
||||
FROM scratch AS update
|
||||
COPY --from=vendored /out /
|
||||
|
||||
FROM vendored AS validate
|
||||
RUN --mount=type=bind,target=.,rw \
|
||||
git add -A && cp -rf /out/* .; \
|
||||
if [ -n "$(git status --porcelain -- yarn.lock)" ]; then \
|
||||
echo >&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor-update"'; \
|
||||
git status --porcelain -- yarn.lock; \
|
||||
exit 1; \
|
||||
fi
|
||||
+1
-1
@@ -8,7 +8,7 @@ module.exports = {
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
testTimeout: 10000,
|
||||
testTimeout: 30000,
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
|
||||
+16
-14
@@ -21,23 +21,25 @@
|
||||
"author": "CrazyMax",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/http-client": "^1.0.8",
|
||||
"@actions/tool-cache": "^1.6.0"
|
||||
"@actions/core": "^1.6.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/http-client": "^1.0.11",
|
||||
"@actions/tool-cache": "^1.7.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"yargs": "^17.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.14",
|
||||
"@types/node": "^14.11.2",
|
||||
"@vercel/ncc": "^0.24.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"jest": "^26.4.2",
|
||||
"jest-circus": "^26.4.2",
|
||||
"jest-runtime": "^26.4.2",
|
||||
"prettier": "^2.1.2",
|
||||
"@types/jest": "^26.0.24",
|
||||
"@types/node": "^14.17.6",
|
||||
"@vercel/ncc": "^0.28.6",
|
||||
"dotenv": "^8.6.0",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"jest-runtime": "^26.6.3",
|
||||
"prettier": "^2.3.2",
|
||||
"tmp": "^0.2.1",
|
||||
"ts-jest": "^26.4.1",
|
||||
"typescript": "^4.0.3",
|
||||
"ts-jest": "^26.5.6",
|
||||
"typescript": "^4.3.5",
|
||||
"typescript-formatter": "^7.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import * as os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
import {issueCommand} from '@actions/core/lib/command';
|
||||
|
||||
export const osPlat: string = os.platform();
|
||||
export const osArch: string = os.arch();
|
||||
|
||||
export interface Inputs {
|
||||
distribution: string;
|
||||
version: string;
|
||||
args: string;
|
||||
workdir: string;
|
||||
installOnly: boolean;
|
||||
}
|
||||
|
||||
export async function getInputs(): Promise<Inputs> {
|
||||
return {
|
||||
distribution: core.getInput('distribution') || 'goreleaser',
|
||||
version: core.getInput('version'),
|
||||
args: core.getInput('args'),
|
||||
workdir: core.getInput('workdir') || '.',
|
||||
installOnly: core.getBooleanInput('install-only')
|
||||
};
|
||||
}
|
||||
|
||||
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
|
||||
export function setOutput(name: string, value: any): void {
|
||||
issueCommand('set-output', {name}, value);
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
import * as actionsExec from '@actions/exec';
|
||||
import {ExecOptions} from '@actions/exec';
|
||||
|
||||
export interface ExecResult {
|
||||
success: boolean;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
|
||||
let stdout: string = '';
|
||||
let stderr: string = '';
|
||||
|
||||
const options: ExecOptions = {
|
||||
silent: silent,
|
||||
ignoreReturnCode: true
|
||||
};
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
stdout += data.toString();
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
stderr += data.toString();
|
||||
}
|
||||
};
|
||||
|
||||
const returnCode: number = await actionsExec.exec(command, args, options);
|
||||
|
||||
return {
|
||||
success: returnCode === 0,
|
||||
stdout: stdout.trim(),
|
||||
stderr: stderr.trim()
|
||||
};
|
||||
};
|
||||
+12
-7
@@ -1,12 +1,17 @@
|
||||
import * as exec from './exec';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
const git = async (args: string[] = []): Promise<string> => {
|
||||
return await exec.exec(`git`, args, true).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
return res.stdout.trim();
|
||||
});
|
||||
return await exec
|
||||
.getExecOutput(`git`, args, {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
})
|
||||
.then(res => {
|
||||
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
return res.stdout.trim();
|
||||
});
|
||||
};
|
||||
|
||||
export async function getTag(): Promise<string> {
|
||||
|
||||
+22
-12
@@ -1,43 +1,53 @@
|
||||
import * as httpm from '@actions/http-client';
|
||||
import * as core from '@actions/core';
|
||||
import * as goreleaser from './goreleaser';
|
||||
import * as semver from 'semver';
|
||||
import * as core from '@actions/core';
|
||||
import * as httpm from '@actions/http-client';
|
||||
|
||||
export interface GitHubRelease {
|
||||
id: number;
|
||||
tag_name: string;
|
||||
}
|
||||
|
||||
export const getRelease = async (version: string): Promise<GitHubRelease | null> => {
|
||||
const resolvedVersion: string = (await resolveVersion(version)) || version;
|
||||
const url: string = `https://github.com/goreleaser/goreleaser/releases/${resolvedVersion}`;
|
||||
export const getRelease = async (distribution: string, version: string): Promise<GitHubRelease | null> => {
|
||||
const resolvedVersion: string = (await resolveVersion(distribution, version)) || version;
|
||||
const url: string = `https://github.com/goreleaser/${distribution}/releases/${resolvedVersion}`;
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
||||
return (await http.getJson<GitHubRelease>(url)).result;
|
||||
};
|
||||
|
||||
const resolveVersion = async (version: string): Promise<string | null> => {
|
||||
const allTags: Array<string> | null = await getAllTags();
|
||||
const resolveVersion = async (distribution: string, version: string): Promise<string | null> => {
|
||||
const allTags: Array<string> | null = await getAllTags(distribution);
|
||||
if (!allTags) {
|
||||
throw new Error(`Cannot find GoReleaser tags`);
|
||||
}
|
||||
core.debug(`Found ${allTags.length} tags in total`);
|
||||
|
||||
return semver.maxSatisfying(allTags, version);
|
||||
if (version === 'latest' || !goreleaser.isPro(distribution)) {
|
||||
return semver.maxSatisfying(allTags, version);
|
||||
}
|
||||
|
||||
const cleanTags: Array<string> = allTags.map(tag => cleanTag(tag));
|
||||
const cleanVersion: string = cleanTag(version);
|
||||
return semver.maxSatisfying(cleanTags, cleanVersion) + goreleaser.distribSuffix(distribution);
|
||||
};
|
||||
|
||||
interface GitHubTag {
|
||||
tag_name: string;
|
||||
}
|
||||
|
||||
const getAllTags = async (): Promise<Array<string>> => {
|
||||
const getAllTags = async (distribution: string): Promise<Array<string>> => {
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('goreleaser-action');
|
||||
const url: string = `https://goreleaser.com/static/releases.json`;
|
||||
const suffix: string = goreleaser.distribSuffix(distribution);
|
||||
const url: string = `https://goreleaser.com/static/releases${suffix}.json`;
|
||||
const getTags = http.getJson<Array<GitHubTag>>(url);
|
||||
|
||||
return getTags.then(response => {
|
||||
if (response.result == null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return response.result.map(obj => obj.tag_name);
|
||||
});
|
||||
};
|
||||
|
||||
const cleanTag = (tag: string): string => {
|
||||
return tag.replace(/-pro$/, '');
|
||||
};
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import yaml from 'js-yaml';
|
||||
import * as context from './context';
|
||||
import * as github from './github';
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
export async function install(distribution: string, version: string): Promise<string> {
|
||||
const release: github.GitHubRelease | null = await github.getRelease(distribution, version);
|
||||
if (!release) {
|
||||
throw new Error(`Cannot find GoReleaser ${version} release`);
|
||||
}
|
||||
|
||||
const filename = getFilename(distribution);
|
||||
const downloadUrl = util.format(
|
||||
'https://github.com/goreleaser/%s/releases/download/%s/%s',
|
||||
distribution,
|
||||
release.tag_name,
|
||||
filename
|
||||
);
|
||||
|
||||
core.info(`Downloading ${downloadUrl}`);
|
||||
const downloadPath: string = await tc.downloadTool(downloadUrl);
|
||||
core.debug(`Downloaded to ${downloadPath}`);
|
||||
|
||||
core.info('Extracting GoReleaser');
|
||||
let extPath: string;
|
||||
if (context.osPlat == 'win32') {
|
||||
extPath = await tc.extractZip(downloadPath);
|
||||
} else {
|
||||
extPath = await tc.extractTar(downloadPath);
|
||||
}
|
||||
core.debug(`Extracted to ${extPath}`);
|
||||
|
||||
const cachePath: string = await tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
||||
core.debug(`Cached to ${cachePath}`);
|
||||
|
||||
const exePath: string = path.join(cachePath, context.osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
||||
core.debug(`Exe path is ${exePath}`);
|
||||
|
||||
return exePath;
|
||||
}
|
||||
|
||||
export const distribSuffix = (distribution: string): string => {
|
||||
return isPro(distribution) ? '-pro' : '';
|
||||
};
|
||||
|
||||
export const isPro = (distribution: string): boolean => {
|
||||
return distribution === 'goreleaser-pro';
|
||||
};
|
||||
|
||||
const getFilename = (distribution: string): string => {
|
||||
let arch: string;
|
||||
switch (context.osArch) {
|
||||
case 'x64': {
|
||||
arch = 'x86_64';
|
||||
break;
|
||||
}
|
||||
case 'x32': {
|
||||
arch = 'i386';
|
||||
break;
|
||||
}
|
||||
case 'arm': {
|
||||
const arm_version = (process.config.variables as any).arm_version;
|
||||
arch = arm_version ? 'armv' + arm_version : 'arm';
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
arch = context.osArch;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (context.osPlat == 'darwin') {
|
||||
arch = 'all';
|
||||
}
|
||||
const platform: string = context.osPlat == 'win32' ? 'Windows' : context.osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
||||
const ext: string = context.osPlat == 'win32' ? 'zip' : 'tar.gz';
|
||||
const suffix: string = distribSuffix(distribution);
|
||||
return util.format('goreleaser%s_%s_%s.%s', suffix, platform, arch, ext);
|
||||
};
|
||||
|
||||
export async function getDistPath(yamlfile: string): Promise<string> {
|
||||
const cfg = yaml.load(yamlfile);
|
||||
return cfg.dist || 'dist';
|
||||
}
|
||||
|
||||
export async function getArtifacts(distpath: string): Promise<string | undefined> {
|
||||
const artifactsFile = path.join(distpath, 'artifacts.json');
|
||||
if (!fs.existsSync(artifactsFile)) {
|
||||
return undefined;
|
||||
}
|
||||
const content = fs.readFileSync(artifactsFile, {encoding: 'utf-8'}).trim();
|
||||
if (content === 'null') {
|
||||
return undefined;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
export async function getMetadata(distpath: string): Promise<string | undefined> {
|
||||
const metadataFile = path.join(distpath, 'metadata.json');
|
||||
if (!fs.existsSync(metadataFile)) {
|
||||
return undefined;
|
||||
}
|
||||
const content = fs.readFileSync(metadataFile, {encoding: 'utf-8'}).trim();
|
||||
if (content === 'null') {
|
||||
return undefined;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as github from './github';
|
||||
import * as core from '@actions/core';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
|
||||
const osPlat: string = os.platform();
|
||||
const osArch: string = os.arch();
|
||||
|
||||
export async function getGoReleaser(version: string): Promise<string> {
|
||||
const release: github.GitHubRelease | null = await github.getRelease(version);
|
||||
if (!release) {
|
||||
throw new Error(`Cannot find GoReleaser ${version} release`);
|
||||
}
|
||||
|
||||
core.info(`✅ GoReleaser version found: ${release.tag_name}`);
|
||||
const filename = getFilename();
|
||||
const downloadUrl = util.format(
|
||||
'https://github.com/goreleaser/goreleaser/releases/download/%s/%s',
|
||||
release.tag_name,
|
||||
filename
|
||||
);
|
||||
|
||||
core.info(`⬇️ Downloading ${downloadUrl}...`);
|
||||
const downloadPath: string = await tc.downloadTool(downloadUrl);
|
||||
core.debug(`Downloaded to ${downloadPath}`);
|
||||
|
||||
core.info('📦 Extracting GoReleaser...');
|
||||
let extPath: string;
|
||||
if (osPlat == 'win32') {
|
||||
extPath = await tc.extractZip(downloadPath);
|
||||
} else {
|
||||
extPath = await tc.extractTar(downloadPath);
|
||||
}
|
||||
core.debug(`Extracted to ${extPath}`);
|
||||
|
||||
const cachePath: string = await tc.cacheDir(extPath, 'goreleaser-action', release.tag_name.replace(/^v/, ''));
|
||||
core.debug(`Cached to ${cachePath}`);
|
||||
|
||||
const exePath: string = path.join(cachePath, osPlat == 'win32' ? 'goreleaser.exe' : 'goreleaser');
|
||||
core.debug(`Exe path is ${exePath}`);
|
||||
|
||||
return exePath;
|
||||
}
|
||||
|
||||
const getFilename = (): string => {
|
||||
const platform: string = osPlat == 'win32' ? 'Windows' : osPlat == 'darwin' ? 'Darwin' : 'Linux';
|
||||
const arch: string = osArch == 'x64' ? 'x86_64' : 'i386';
|
||||
const ext: string = osPlat == 'win32' ? 'zip' : 'tar.gz';
|
||||
return util.format('goreleaser_%s_%s.%s', platform, arch, ext);
|
||||
};
|
||||
+61
-14
@@ -1,38 +1,85 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import * as context from './context';
|
||||
import * as git from './git';
|
||||
import * as installer from './installer';
|
||||
import * as goreleaser from './goreleaser';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const version = core.getInput('version') || 'latest';
|
||||
const args = core.getInput('args', {required: true});
|
||||
const workdir = core.getInput('workdir') || '.';
|
||||
const goreleaser = await installer.getGoReleaser(version);
|
||||
const inputs: context.Inputs = await context.getInputs();
|
||||
const bin = await goreleaser.install(inputs.distribution, inputs.version);
|
||||
core.info(`GoReleaser ${inputs.version} installed successfully`);
|
||||
|
||||
if (workdir && workdir !== '.') {
|
||||
core.info(`📂 Using ${workdir} as working directory...`);
|
||||
process.chdir(workdir);
|
||||
if (inputs.installOnly) {
|
||||
const goreleaserDir = path.dirname(bin);
|
||||
core.addPath(goreleaserDir);
|
||||
core.debug(`Added ${goreleaserDir} to PATH`);
|
||||
return;
|
||||
} else if (!inputs.args) {
|
||||
core.setFailed('args input required');
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputs.workdir && inputs.workdir !== '.') {
|
||||
core.info(`Using ${inputs.workdir} as working directory`);
|
||||
process.chdir(inputs.workdir);
|
||||
}
|
||||
|
||||
const commit = await git.getShortCommit();
|
||||
const tag = await git.getTag();
|
||||
const isTagDirty = await git.isTagDirty(tag);
|
||||
|
||||
let yamlfile: string | unknown;
|
||||
const argv = yargs.parse(inputs.args);
|
||||
if (argv.config) {
|
||||
yamlfile = argv.config;
|
||||
} else {
|
||||
['.goreleaser.yaml', '.goreleaser.yml', 'goreleaser.yaml', 'goreleaser.yml'].forEach(f => {
|
||||
if (fs.existsSync(f)) {
|
||||
yamlfile = f;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let snapshot = '';
|
||||
if (args.split(' ').indexOf('release') > -1) {
|
||||
if (inputs.args.split(' ').indexOf('release') > -1) {
|
||||
if (isTagDirty) {
|
||||
core.info(`⚠️ No tag found for commit ${commit}. Snapshot forced`);
|
||||
if (!args.includes('--snapshot')) {
|
||||
if (!inputs.args.includes('--snapshot') && !inputs.args.includes('--nightly')) {
|
||||
core.info(`No tag found for commit ${commit}. Snapshot forced`);
|
||||
snapshot = ' --snapshot';
|
||||
}
|
||||
} else {
|
||||
core.info(`✅ ${tag} tag found for commit ${commit}`);
|
||||
core.info(`${tag} tag found for commit ${commit}`);
|
||||
}
|
||||
}
|
||||
|
||||
core.info('🏃 Running GoReleaser...');
|
||||
await exec.exec(`${goreleaser} ${args}${snapshot}`);
|
||||
await exec.exec(`${bin} ${inputs.args}${snapshot}`, undefined, {
|
||||
env: Object.assign({}, process.env, {
|
||||
GORELEASER_CURRENT_TAG: process.env.GORELEASER_CURRENT_TAG || tag || ''
|
||||
}) as {
|
||||
[key: string]: string;
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof yamlfile === 'string') {
|
||||
const artifacts = await goreleaser.getArtifacts(await goreleaser.getDistPath(yamlfile));
|
||||
if (artifacts) {
|
||||
await core.group(`Artifacts output`, async () => {
|
||||
core.info(artifacts);
|
||||
context.setOutput('artifacts', artifacts);
|
||||
});
|
||||
}
|
||||
const metadata = await goreleaser.getMetadata(await goreleaser.getDistPath(yamlfile));
|
||||
if (metadata) {
|
||||
await core.group(`Metadata output`, async () => {
|
||||
core.info(metadata);
|
||||
context.setOutput('metadata', metadata);
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
- GOPROXY=https://goproxy.io
|
||||
|
||||
before:
|
||||
hooks:
|
||||
@@ -26,10 +25,6 @@ archives:
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- LICENSE
|
||||
- README.md
|
||||
- CHANGELOG.md
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
@@ -1,6 +1,5 @@
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
- GOPROXY=https://goproxy.io
|
||||
|
||||
before:
|
||||
hooks:
|
||||
@@ -26,10 +25,6 @@ archives:
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
files:
|
||||
- LICENSE
|
||||
- README.md
|
||||
- CHANGELOG.md
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
@@ -1,3 +1,3 @@
|
||||
module github.com/goreleaser/goreleaser-action
|
||||
|
||||
go 1.14
|
||||
go 1.15
|
||||
+2
-1
@@ -3,7 +3,8 @@
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"newLine": "lf",
|
||||
"outDir": "./lib",
|
||||
|
||||
Reference in New Issue
Block a user