mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-10 11:47:03 +00:00
Compare commits
20 commits
f4f27ffacd
...
1750e222f7
| Author | SHA1 | Date | |
|---|---|---|---|
| 1750e222f7 | |||
| dda12c62c7 | |||
| 7f69971116 | |||
| f077b647e7 | |||
| 44b76e55f8 | |||
| e83a7c9a23 | |||
|
|
563885899c | ||
|
|
16ba2c6b09 | ||
|
|
e6c8f3f93b | ||
| e6503da93a | |||
|
|
5b5b29c0b5 | ||
| c768260a2e | |||
| b3cb9e128c | |||
| d259921215 | |||
| 48b1894cac | |||
| 5306e2dd35 | |||
| f1aa1a2ef4 | |||
|
|
1e9e0aa5d9 | ||
|
|
6237c9b666 | ||
|
|
2f7e8b9afe |
35 changed files with 464 additions and 123 deletions
16
.github/actions/setup-mdbook/action.yaml
vendored
16
.github/actions/setup-mdbook/action.yaml
vendored
|
|
@ -1,16 +0,0 @@
|
||||||
name: "Setup mdbook"
|
|
||||||
inputs:
|
|
||||||
version:
|
|
||||||
description: "mdbook version"
|
|
||||||
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- name: Setup mdbook
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
url: https://github.com/rust-lang/mdbook/releases/download/${{ inputs.version }}/mdbook-${{ inputs.version }}-x86_64-unknown-linux-gnu.tar.gz
|
|
||||||
run: |
|
|
||||||
mkdir mdbook
|
|
||||||
curl -sSL "$url" | tar -xz --directory=./mdbook
|
|
||||||
echo `pwd`/mdbook >> $GITHUB_PATH
|
|
||||||
9
.github/renovate.json5
vendored
9
.github/renovate.json5
vendored
|
|
@ -69,6 +69,15 @@
|
||||||
': (?<currentValue>.+) # renovate: datasource=(?<datasource>[a-z-]+) depName=(?<depName>[^\\s]+)(?: lookupName=(?<packageName>[^\\s]+))?(?: versioning=(?<versioning>[a-z-]+))?(?: extractVersion=(?<extractVersion>[^\\s]+))?',
|
': (?<currentValue>.+) # renovate: datasource=(?<datasource>[a-z-]+) depName=(?<depName>[^\\s]+)(?: lookupName=(?<packageName>[^\\s]+))?(?: versioning=(?<versioning>[a-z-]+))?(?: extractVersion=(?<extractVersion>[^\\s]+))?',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
customType: 'regex',
|
||||||
|
managerFilePatterns: [
|
||||||
|
'/.+\\.toml$/'
|
||||||
|
],
|
||||||
|
matchStrings: [
|
||||||
|
'= "(?<currentValue>.+)" # renovate: datasource=(?<datasource>[a-z-]+) depName=(?<depName>[^\\s]+)(?: lookupName=(?<packageName>[^\\s]+))?(?: versioning=(?<versioning>[a-z-]+))?(?: extractVersion=(?<extractVersion>[^\\s]+))?',
|
||||||
|
],
|
||||||
|
}
|
||||||
],
|
],
|
||||||
postUpdateOptions: [
|
postUpdateOptions: [
|
||||||
'gomodUpdateImportPaths',
|
'gomodUpdateImportPaths',
|
||||||
|
|
|
||||||
27
.github/workflows/ci.yaml
vendored
27
.github/workflows/ci.yaml
vendored
|
|
@ -2,7 +2,7 @@ name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [ main ]
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -10,35 +10,29 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
|
|
||||||
- name: Set up Go
|
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3
|
||||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Run golangci-lint
|
- name: Run golangci-lint
|
||||||
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8
|
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8
|
||||||
with:
|
with:
|
||||||
version: v2.4.0 # renovate: datasource=github-releases depName=golangci/golangci-lint
|
install-mode: none
|
||||||
args: --timeout 5m
|
args: --timeout 5m
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
|
|
||||||
- name: Set up Go
|
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3
|
||||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: go test -v -race -coverpkg=./... -coverprofile=coverage.txt ./...
|
run: go test -v -race -coverpkg=./... -coverprofile=coverage.txt ./...
|
||||||
|
|
||||||
- name: Upload results to Codecov
|
- name: Upload results to Codecov
|
||||||
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5
|
uses: codecov/codecov-action@fdcc8476540edceab3de004e990f80d881c6cc00 # v5
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
flags: unit
|
flags: unit
|
||||||
|
|
@ -75,12 +69,9 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
|
|
||||||
- name: Set up Go
|
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3
|
||||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- name: Run go mod tidy
|
- name: Run go mod tidy
|
||||||
run: go mod tidy
|
run: go mod tidy
|
||||||
|
|
|
||||||
8
.github/workflows/docs.yaml
vendored
8
.github/workflows/docs.yaml
vendored
|
|
@ -13,14 +13,10 @@ jobs:
|
||||||
id-token: write # To update the deployment status
|
id-token: write # To update the deployment status
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
with:
|
with:
|
||||||
lfs: "true"
|
lfs: "true"
|
||||||
|
|
||||||
- uses: ./.github/actions/setup-mdbook
|
|
||||||
with:
|
|
||||||
version: v0.4.52 # renovate: datasource=github-releases depName=rust-lang/mdbook
|
|
||||||
|
|
||||||
- name: Build Book
|
- name: Build Book
|
||||||
working-directory: docs
|
working-directory: docs
|
||||||
run: mdbook build
|
run: mdbook build
|
||||||
|
|
@ -29,7 +25,7 @@ jobs:
|
||||||
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
|
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
|
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4
|
||||||
with:
|
with:
|
||||||
# Upload entire repository
|
# Upload entire repository
|
||||||
path: "docs/book"
|
path: "docs/book"
|
||||||
|
|
|
||||||
2
.github/workflows/mirror.yaml
vendored
2
.github/workflows/mirror.yaml
vendored
|
|
@ -11,7 +11,7 @@ jobs:
|
||||||
REMOTE: mirror
|
REMOTE: mirror
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
with:
|
with:
|
||||||
# Need all to fetch all tags so we can push them
|
# Need all to fetch all tags so we can push them
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
|
||||||
8
.github/workflows/release.yaml
vendored
8
.github/workflows/release.yaml
vendored
|
|
@ -14,12 +14,8 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
|
|
||||||
- name: Set up Go
|
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3
|
||||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
|
|
||||||
- run: ko build --bare --tags ${{ github.ref_name }} github.com/apricote/releaser-pleaser/cmd/rp
|
- run: ko build --bare --tags ${{ github.ref_name }} github.com/apricote/releaser-pleaser/cmd/rp
|
||||||
|
|
|
||||||
12
.github/workflows/releaser-pleaser.yaml
vendored
12
.github/workflows/releaser-pleaser.yaml
vendored
|
|
@ -2,7 +2,7 @@ name: releaser-pleaser
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [ main ]
|
||||||
# Using pull_request_target to avoid tainting the actual release PR with code from open feature pull requests
|
# Using pull_request_target to avoid tainting the actual release PR with code from open feature pull requests
|
||||||
pull_request_target:
|
pull_request_target:
|
||||||
types:
|
types:
|
||||||
|
|
@ -17,7 +17,7 @@ concurrency:
|
||||||
group: releaser-pleaser
|
group: releaser-pleaser
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
permissions: {}
|
permissions: { }
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
releaser-pleaser:
|
releaser-pleaser:
|
||||||
|
|
@ -25,19 +25,15 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
|
|
||||||
- name: Set up Go
|
- uses: jdx/mise-action@5ac50f778e26fac95da98d50503682459e86d566 # v3
|
||||||
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
|
|
||||||
with:
|
|
||||||
go-version-file: go.mod
|
|
||||||
|
|
||||||
# Build container image from current commit and replace image ref in `action.yml`
|
# Build container image from current commit and replace image ref in `action.yml`
|
||||||
# Without this, any new flags in `action.yml` would break the job in this repository until the new
|
# Without this, any new flags in `action.yml` would break the job in this repository until the new
|
||||||
# version is released. But a new version can only be released if this job works.
|
# version is released. But a new version can only be released if this job works.
|
||||||
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
|
|
||||||
- run: ko build --bare --local --platform linux/amd64 --tags ci github.com/apricote/releaser-pleaser/cmd/rp
|
- run: ko build --bare --local --platform linux/amd64 --tags ci github.com/apricote/releaser-pleaser/cmd/rp
|
||||||
|
|
||||||
- run: mkdir -p .github/actions/releaser-pleaser
|
- run: mkdir -p .github/actions/releaser-pleaser
|
||||||
|
|
|
||||||
22
CHANGELOG.md
22
CHANGELOG.md
|
|
@ -1,5 +1,27 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [v0.7.0](https://github.com/apricote/releaser-pleaser/releases/tag/v0.7.0)
|
||||||
|
|
||||||
|
### Highlights :sparkles:
|
||||||
|
|
||||||
|
#### Update version in `package.json`
|
||||||
|
|
||||||
|
Thanks to @Mattzi it is now possible to use `releaser-pleaser` in Javascript/Node.js projects with a `package.json` file.
|
||||||
|
|
||||||
|
You can enable this with the option `updaters: packagejson` in the GitHub Actions / GitLab CI/CD config.
|
||||||
|
|
||||||
|
All updaters, including the defaults `changelog` and `generic` can now be enabled and disabled through this field. You can find a full list in the [documentation](https://apricote.github.io/releaser-pleaser/reference/updaters.html).
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- add updater for package.json (#213)
|
||||||
|
- highlight breaking changes in release notes (#234)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- filter out empty updaters in input (#235)
|
||||||
|
- **github**: duplicate release pr when process is stopped at wrong moment (#236)
|
||||||
|
|
||||||
## [v0.6.1](https://github.com/apricote/releaser-pleaser/releases/tag/v0.6.1)
|
## [v0.6.1](https://github.com/apricote/releaser-pleaser/releases/tag/v0.6.1)
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
|
||||||
11
action.yml
11
action.yml
|
|
@ -14,19 +14,24 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.token }}
|
default: ${{ github.token }}
|
||||||
extra-files:
|
extra-files:
|
||||||
description: 'List of files that are scanned for version references.'
|
description: 'List of files that are scanned for version references by the generic updater.'
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
updaters:
|
||||||
|
description: "List of updaters that are run. Default updaters can be removed by specifying them as -name. Multiple updaters should be concatenated with a comma. Default Updaters: changelog,generic"
|
||||||
required: false
|
required: false
|
||||||
default: ""
|
default: ""
|
||||||
# Remember to update docs/reference/github-action.md
|
# Remember to update docs/reference/github-action.md
|
||||||
outputs: {}
|
outputs: { }
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: docker://ghcr.io/apricote/releaser-pleaser:v0.6.1 # x-releaser-pleaser-version
|
image: docker://ghcr.io/apricote/releaser-pleaser:v0.7.0 # x-releaser-pleaser-version
|
||||||
args:
|
args:
|
||||||
- run
|
- run
|
||||||
- --forge=github
|
- --forge=github
|
||||||
- --branch=${{ inputs.branch }}
|
- --branch=${{ inputs.branch }}
|
||||||
- --extra-files="${{ inputs.extra-files }}"
|
- --extra-files="${{ inputs.extra-files }}"
|
||||||
|
- --updaters="${{ inputs.updaters }}"
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: "${{ inputs.token }}"
|
GITHUB_TOKEN: "${{ inputs.token }}"
|
||||||
GITHUB_USER: "oauth2"
|
GITHUB_USER: "oauth2"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
@ -25,6 +26,7 @@ func newRunCommand() *cobra.Command {
|
||||||
flagOwner string
|
flagOwner string
|
||||||
flagRepo string
|
flagRepo string
|
||||||
flagExtraFiles string
|
flagExtraFiles string
|
||||||
|
flagUpdaters []string
|
||||||
|
|
||||||
flagAPIURL string
|
flagAPIURL string
|
||||||
flagAPIToken string
|
flagAPIToken string
|
||||||
|
|
@ -92,6 +94,21 @@ func newRunCommand() *cobra.Command {
|
||||||
|
|
||||||
extraFiles := parseExtraFiles(flagExtraFiles)
|
extraFiles := parseExtraFiles(flagExtraFiles)
|
||||||
|
|
||||||
|
updaterNames := parseUpdaters(flagUpdaters)
|
||||||
|
updaters := []updater.Updater{}
|
||||||
|
for _, name := range updaterNames {
|
||||||
|
switch name {
|
||||||
|
case "generic":
|
||||||
|
updaters = append(updaters, updater.Generic(extraFiles))
|
||||||
|
case "changelog":
|
||||||
|
updaters = append(updaters, updater.Changelog())
|
||||||
|
case "packagejson":
|
||||||
|
updaters = append(updaters, updater.PackageJson())
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("unknown updater: %s", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
releaserPleaser := rp.New(
|
releaserPleaser := rp.New(
|
||||||
f,
|
f,
|
||||||
logger,
|
logger,
|
||||||
|
|
@ -99,7 +116,7 @@ func newRunCommand() *cobra.Command {
|
||||||
conventionalcommits.NewParser(logger),
|
conventionalcommits.NewParser(logger),
|
||||||
versioning.SemVer,
|
versioning.SemVer,
|
||||||
extraFiles,
|
extraFiles,
|
||||||
[]updater.NewUpdater{updater.Generic},
|
updaters,
|
||||||
)
|
)
|
||||||
|
|
||||||
return releaserPleaser.Run(ctx)
|
return releaserPleaser.Run(ctx)
|
||||||
|
|
@ -111,6 +128,8 @@ func newRunCommand() *cobra.Command {
|
||||||
cmd.PersistentFlags().StringVar(&flagOwner, "owner", "", "")
|
cmd.PersistentFlags().StringVar(&flagOwner, "owner", "", "")
|
||||||
cmd.PersistentFlags().StringVar(&flagRepo, "repo", "", "")
|
cmd.PersistentFlags().StringVar(&flagRepo, "repo", "", "")
|
||||||
cmd.PersistentFlags().StringVar(&flagExtraFiles, "extra-files", "", "")
|
cmd.PersistentFlags().StringVar(&flagExtraFiles, "extra-files", "", "")
|
||||||
|
cmd.PersistentFlags().StringSliceVar(&flagUpdaters, "updaters", []string{}, "")
|
||||||
|
|
||||||
cmd.PersistentFlags().StringVar(&flagAPIURL, "api-url", "", "")
|
cmd.PersistentFlags().StringVar(&flagAPIURL, "api-url", "", "")
|
||||||
cmd.PersistentFlags().StringVar(&flagAPIToken, "api-token", "", "")
|
cmd.PersistentFlags().StringVar(&flagAPIToken, "api-token", "", "")
|
||||||
cmd.PersistentFlags().StringVar(&flagUsername, "username", "", "")
|
cmd.PersistentFlags().StringVar(&flagUsername, "username", "", "")
|
||||||
|
|
@ -137,3 +156,26 @@ func parseExtraFiles(input string) []string {
|
||||||
|
|
||||||
return extraFiles
|
return extraFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseUpdaters(input []string) []string {
|
||||||
|
names := []string{"changelog", "generic"}
|
||||||
|
|
||||||
|
for _, u := range input {
|
||||||
|
if u == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(u, "-") {
|
||||||
|
name := u[1:]
|
||||||
|
names = slices.DeleteFunc(names, func(existingName string) bool { return existingName == name })
|
||||||
|
} else {
|
||||||
|
names = append(names, u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we only have unique updaters
|
||||||
|
slices.Sort(names)
|
||||||
|
names = slices.Compact(names)
|
||||||
|
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,3 +57,48 @@ dir/Chart.yaml"`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_parseUpdaters(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input []string
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty",
|
||||||
|
input: []string{},
|
||||||
|
want: []string{"changelog", "generic"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "remove defaults",
|
||||||
|
input: []string{"-changelog", "-generic"},
|
||||||
|
want: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "remove unknown is ignored",
|
||||||
|
input: []string{"-fooo"},
|
||||||
|
want: []string{"changelog", "generic"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "add new entry",
|
||||||
|
input: []string{"bar"},
|
||||||
|
want: []string{"bar", "changelog", "generic"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "duplicates are removed",
|
||||||
|
input: []string{"bar", "bar", "changelog"},
|
||||||
|
want: []string{"bar", "changelog", "generic"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "remove empty entries",
|
||||||
|
input: []string{""},
|
||||||
|
want: []string{"changelog", "generic"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got := parseUpdaters(tt.input)
|
||||||
|
assert.Equal(t, tt.want, got)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
- [Pull Request Options](reference/pr-options.md)
|
- [Pull Request Options](reference/pr-options.md)
|
||||||
- [GitHub Action](reference/github-action.md)
|
- [GitHub Action](reference/github-action.md)
|
||||||
- [GitLab CI/CD Component](reference/gitlab-cicd-component.md)
|
- [GitLab CI/CD Component](reference/gitlab-cicd-component.md)
|
||||||
|
- [Updaters](reference/updaters.md)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ In some situations it makes sense to have the current version committed in files
|
||||||
|
|
||||||
## Markers
|
## Markers
|
||||||
|
|
||||||
The line that needs to be updated must have the marker `x-releaser-pleaser-version` somewhere after the version that should be updated.
|
The line that needs to be updated must have the marker
|
||||||
|
`x-releaser-pleaser-version` somewhere after the version that should be updated.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
|
|
@ -28,7 +29,8 @@ You need to tell `releaser-pleaser` which files it should update. This happens t
|
||||||
|
|
||||||
### GitHub Action
|
### GitHub Action
|
||||||
|
|
||||||
In the GitHub Action you can set the `extra-files` input with a list of the files. They need to be formatted as a single multi-line string with one file path per line:
|
In the GitHub Action you can set the
|
||||||
|
`extra-files` input with a list of the files. They need to be formatted as a single multi-line string with one file path per line:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
|
|
@ -44,7 +46,8 @@ jobs:
|
||||||
|
|
||||||
### GitLab CI/CD Component
|
### GitLab CI/CD Component
|
||||||
|
|
||||||
In the GitLab CI/CD Component you can set the `extra-files` input with a list of files. They need to be formatted as a single multi-line string with one file path per line:
|
In the GitLab CI/CD Component you can set the
|
||||||
|
`extra-files` input with a list of files. They need to be formatted as a single multi-line string with one file path per line:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
include:
|
include:
|
||||||
|
|
@ -61,3 +64,4 @@ include:
|
||||||
- **Reference**
|
- **Reference**
|
||||||
- [GitHub Action](../reference/github-action.md#inputs)
|
- [GitHub Action](../reference/github-action.md#inputs)
|
||||||
- [GitLab CI/CD Component](../reference/gitlab-cicd-component.md#inputs)
|
- [GitLab CI/CD Component](../reference/gitlab-cicd-component.md#inputs)
|
||||||
|
- [Updaters](../reference/updaters.md#generic-updater)
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,20 @@ The action is available as `apricote/releaser-pleaser` on GitHub.com.
|
||||||
|
|
||||||
The `apricote/releaser-pleaser` action is released together with `releaser-pleaser` and they share the version number.
|
The `apricote/releaser-pleaser` action is released together with `releaser-pleaser` and they share the version number.
|
||||||
|
|
||||||
The action does not support floating tags (e.g. `v1`) right now ([#31](https://github.com/apricote/releaser-pleaser/issues/31)). You have to use the full version or commit SHA instead: `apricote/releaser-pleaser@v0.2.0`.
|
The action does not support floating tags (e.g.
|
||||||
|
`v1`) right now ([#31](https://github.com/apricote/releaser-pleaser/issues/31)). You have to use the full version or commit SHA instead:
|
||||||
|
`apricote/releaser-pleaser@v0.2.0`.
|
||||||
|
|
||||||
## Inputs
|
## Inputs
|
||||||
|
|
||||||
The following inputs are supported by the `apricote/releaser-pleaser` GitHub Action.
|
The following inputs are supported by the `apricote/releaser-pleaser` GitHub Action.
|
||||||
|
|
||||||
| Input | Description | Default | Example |
|
| Input | Description | Default | Example |
|
||||||
| ------------- | :----------------------------------------------------- | --------------: | -------------------------------------------------------------------: |
|
|---------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------:|---------------------------------------------------------------------:|
|
||||||
| `branch` | This branch is used as the target for releases. | `main` | `master` |
|
| `branch` | This branch is used as the target for releases. | `main` | `master` |
|
||||||
| `token` | GitHub token for creating and updating release PRs | `$GITHUB_TOKEN` | `${{secrets.RELEASER_PLEASER_TOKEN}}` |
|
| `token` | GitHub token for creating and updating release PRs | `$GITHUB_TOKEN` | `${{secrets.RELEASER_PLEASER_TOKEN}}` |
|
||||||
| `extra-files` | List of files that are scanned for version references. | `""` | <pre><code>version/version.go<br>deploy/deployment.yaml</code></pre> |
|
| `extra-files` | List of files that are scanned for version references by the generic updater. | `""` | <pre><code>version/version.go<br>deploy/deployment.yaml</code></pre> |
|
||||||
|
| `updaters` | List of updaters that are run. Default updaters can be removed by specifying them as -name. Multiple updaters should be concatenated with a comma. Default Updaters: changelog,generic | `""` | `-generic,packagejson` |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@ The component does not support floating tags (e.g.
|
||||||
|
|
||||||
The following inputs are supported by the component.
|
The following inputs are supported by the component.
|
||||||
|
|
||||||
| Input | Description | Default | Example |
|
| Input | Description | Default | Example |
|
||||||
| ---------------------- | :-------------------------------------------------------- | ------: | -------------------------------------------------------------------: |
|
|------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------:|---------------------------------------------------------------------:|
|
||||||
| `branch` | This branch is used as the target for releases. | `main` | `master` |
|
| `branch` | This branch is used as the target for releases. | `main` | `master` |
|
||||||
| `token` (**required**) | GitLab access token for creating and updating release PRs | | `$RELEASER_PLEASER_TOKEN` |
|
| `token` (**required**) | GitLab access token for creating and updating release PRs | | `$RELEASER_PLEASER_TOKEN` |
|
||||||
| `extra-files` | List of files that are scanned for version references. | `""` | <pre><code>version/version.go<br>deploy/deployment.yaml</code></pre> |
|
| `extra-files` | List of files that are scanned for version references by the generic updater. | `""` | <pre><code>version/version.go<br>deploy/deployment.yaml</code></pre> |
|
||||||
| `stage` | Stage the job runs in. Must exists. | `build` | `test` |
|
| `updaters` | List of updaters that are run. Default updaters can be removed by specifying them as -name. Multiple updaters should be concatenated with a comma. Default Updaters: changelog,generic | `""` | `-generic,packagejson` |
|
||||||
| `needs` | Other jobs the releaser-pleaser job depends on. | `[]` | <pre><code>- validate-foo<br>- prepare-bar</code></pre> |
|
| `stage` | Stage the job runs in. Must exists. | `build` | `test` |
|
||||||
|
| `needs` | Other jobs the releaser-pleaser job depends on. | `[]` | <pre><code>- validate-foo<br>- prepare-bar</code></pre> |
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,21 @@
|
||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
|
|
||||||
The Changelog is a file in the repository (`CHANGELOG.md`) that contains the [Release Notes](#release-notes) for every release of that repository. Usually, new releases are added at the top of the file.
|
The Changelog is a file in the repository (
|
||||||
|
`CHANGELOG.md`) that contains the [Release Notes](#release-notes) for every release of that repository. Usually, new releases are added at the top of the file.
|
||||||
|
|
||||||
### Conventional Commits
|
### Conventional Commits
|
||||||
|
|
||||||
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is a specification for commit messages. It is the only supported commit message schema in `releaser-pleaser`. Follow the link to learn more.
|
[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is a specification for commit messages. It is the only supported commit message schema in
|
||||||
|
`releaser-pleaser`. Follow the link to learn more.
|
||||||
|
|
||||||
### Forge
|
### Forge
|
||||||
|
|
||||||
A **forge** is a web-based collaborative software platform for both developing and sharing computer applications.[^wp-forge]
|
A **forge
|
||||||
|
** is a web-based collaborative software platform for both developing and sharing computer applications.[^wp-forge]
|
||||||
|
|
||||||
Right now only **GitHub** is supported. We plan to support **GitLab** in the future ([#4](https://github.com/apricote/releaser-pleaser/issues/4)). For other forges like Forgejo or Gitea, please open an issue and submit a pull request.
|
Right now only **GitHub** is supported. We plan to support **GitLab
|
||||||
|
** in the future ([#4](https://github.com/apricote/releaser-pleaser/issues/4)). For other forges like Forgejo or Gitea, please open an issue and submit a pull request.
|
||||||
|
|
||||||
[^wp-forge]: Quote from [Wikipedia "Forge (software)"](<https://en.wikipedia.org/wiki/Forge_(software)>)
|
[^wp-forge]: Quote from [Wikipedia "Forge (software)"](<https://en.wikipedia.org/wiki/Forge_(software)>)
|
||||||
|
|
||||||
|
|
@ -24,7 +28,8 @@ In `releaser-pleaser` Markdown is used for most texts.
|
||||||
|
|
||||||
### Pre-release
|
### Pre-release
|
||||||
|
|
||||||
Pre-releases are a concept of [SemVer](#semantic-versioning-semver). They follow the normal versioning schema but use a suffix out of `-alpha.X`, `-beta.X` and `-rc.X`.
|
Pre-releases are a concept of [SemVer](#semantic-versioning-semver). They follow the normal versioning schema but use a suffix out of
|
||||||
|
`-alpha.X`, `-beta.X` and `-rc.X`.
|
||||||
|
|
||||||
Pre-releases are not considered "stable" and are usually not recommended for most users.
|
Pre-releases are not considered "stable" and are usually not recommended for most users.
|
||||||
|
|
||||||
|
|
@ -32,7 +37,9 @@ Learn more in the [Pre-releases](../guides/pre-releases.md) guide.
|
||||||
|
|
||||||
### Release Pull Request
|
### Release Pull Request
|
||||||
|
|
||||||
A Release Pull Request is opened by `releaser-pleaser` whenever it finds releasable commits in your project. It proposes a new version number and the Changelog. Once it is merged, `releaser-pleaser` creates a matching release.
|
A Release Pull Request is opened by
|
||||||
|
`releaser-pleaser` whenever it finds releasable commits in your project. It proposes a new version number and the Changelog. Once it is merged,
|
||||||
|
`releaser-pleaser` creates a matching release.
|
||||||
|
|
||||||
Learn more in the [Release Pull Request](../explanation/release-pr.md) explanation.
|
Learn more in the [Release Pull Request](../explanation/release-pr.md) explanation.
|
||||||
|
|
||||||
|
|
@ -44,4 +51,11 @@ Learn more in the [Release Notes customization](../guides/release-notes.md) guid
|
||||||
|
|
||||||
### Semantic Versioning (SemVer)
|
### Semantic Versioning (SemVer)
|
||||||
|
|
||||||
[Semantic Versioning](https://semver.org/) is a specification for version numbers. It is the only supported versioning schema in `releaser-pleaser`. Follow the link to learn more.
|
[Semantic Versioning](https://semver.org/) is a specification for version numbers. It is the only supported versioning schema in
|
||||||
|
`releaser-pleaser`. Follow the link to learn more.
|
||||||
|
|
||||||
|
### Updater
|
||||||
|
|
||||||
|
Updaters can update or create files that will be included in [Release Pull Request](#release-pull-request). Examples of Updaters are
|
||||||
|
`changelog` for `CHANGELOG.md`, `generic` that can update arbitrary files and
|
||||||
|
`packagejson` that knows how to update Node.JS `package.json` files.
|
||||||
33
docs/reference/updaters.md
Normal file
33
docs/reference/updaters.md
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
# Updaters
|
||||||
|
|
||||||
|
There are different updater for different purposes available.
|
||||||
|
|
||||||
|
They each have a name and may be enabled by default. You can configure which updaters are used through the
|
||||||
|
`updaters` input on GitHub Actions and GitLab CI/CD. This is a comma-delimited list of updaters that should be enabled, for updaters that are enabled by default you can remove them by adding a minus before its name:
|
||||||
|
|
||||||
|
```
|
||||||
|
updaters: -generic,packagejson
|
||||||
|
```
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
- **Name**: `changelog`
|
||||||
|
- **Default**: enabled
|
||||||
|
|
||||||
|
This updater creates the `CHANGELOG.md` file and adds new release notes to it.
|
||||||
|
|
||||||
|
## Generic Updater
|
||||||
|
|
||||||
|
- **Name**: `generic`
|
||||||
|
- **Default**: enabled
|
||||||
|
|
||||||
|
This updater can update any file and only needs a marker on the line. It is enabled by default.
|
||||||
|
|
||||||
|
Learn more about this updater in ["Updating arbitrary files"](../guides/updating-arbitrary-files.md).
|
||||||
|
|
||||||
|
## Node.js `package.json` Updater
|
||||||
|
|
||||||
|
- **Name**: `packagejson`
|
||||||
|
- **Default**: disabled
|
||||||
|
|
||||||
|
This updater can update the `version` field in Node.js `package.json` files. The updater is disabled by default.
|
||||||
4
go.mod
4
go.mod
|
|
@ -2,14 +2,14 @@ module github.com/apricote/releaser-pleaser
|
||||||
|
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
toolchain go1.24.6
|
toolchain go1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2 v2.0.0-00010101000000-000000000000
|
codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2 v2.0.0-00010101000000-000000000000
|
||||||
github.com/blang/semver/v4 v4.0.0
|
github.com/blang/semver/v4 v4.0.0
|
||||||
github.com/go-git/go-billy/v5 v5.6.2
|
github.com/go-git/go-billy/v5 v5.6.2
|
||||||
github.com/go-git/go-git/v5 v5.16.2
|
github.com/go-git/go-git/v5 v5.16.2
|
||||||
github.com/google/go-github/v72 v72.0.0
|
github.com/google/go-github/v74 v74.0.0
|
||||||
github.com/leodido/go-conventionalcommits v0.12.0
|
github.com/leodido/go-conventionalcommits v0.12.0
|
||||||
github.com/lmittmann/tint v1.1.2
|
github.com/lmittmann/tint v1.1.2
|
||||||
github.com/spf13/cobra v1.9.1
|
github.com/spf13/cobra v1.9.1
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -48,8 +48,8 @@ github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUv
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/go-github/v72 v72.0.0 h1:FcIO37BLoVPBO9igQQ6tStsv2asG4IPcYFi655PPvBM=
|
github.com/google/go-github/v74 v74.0.0 h1:yZcddTUn8DPbj11GxnMrNiAnXH14gNs559AsUpNpPgM=
|
||||||
github.com/google/go-github/v72 v72.0.0/go.mod h1:WWtw8GMRiL62mvIquf1kO3onRHeWWKmK01qdCY8c5fg=
|
github.com/google/go-github/v74 v74.0.0/go.mod h1:ubn/YdyftV80VPSI26nSJvaEsTOnsjrxG3o9kJhcyak=
|
||||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{{define "entry" -}}
|
{{define "entry" -}}
|
||||||
- {{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
|
- {{ if .BreakingChange}}**BREAKING**: {{end}}{{ if .Scope }}**{{.Scope}}**: {{end}}{{.Description}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{- if not .Formatting.HideVersionTitle }}
|
{{- if not .Formatting.HideVersionTitle }}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,23 @@ func Test_NewChangelogEntry(t *testing.T) {
|
||||||
want: "## [1.0.0](https://example.com/1.0.0)\n\n### Features\n\n- Foobar!\n",
|
want: "## [1.0.0](https://example.com/1.0.0)\n\n### Features\n\n- Foobar!\n",
|
||||||
wantErr: assert.NoError,
|
wantErr: assert.NoError,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "single breaking change",
|
||||||
|
args: args{
|
||||||
|
analyzedCommits: []commitparser.AnalyzedCommit{
|
||||||
|
{
|
||||||
|
Commit: git.Commit{},
|
||||||
|
Type: "feat",
|
||||||
|
Description: "Foobar!",
|
||||||
|
BreakingChange: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
version: "1.0.0",
|
||||||
|
link: "https://example.com/1.0.0",
|
||||||
|
},
|
||||||
|
want: "## [1.0.0](https://example.com/1.0.0)\n\n### Features\n\n- **BREAKING**: Foobar!\n",
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "single fix",
|
name: "single fix",
|
||||||
args: args{
|
args: args{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/blang/semver/v4"
|
"github.com/blang/semver/v4"
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||||
"github.com/google/go-github/v72/github"
|
"github.com/google/go-github/v74/github"
|
||||||
|
|
||||||
"github.com/apricote/releaser-pleaser/internal/forge"
|
"github.com/apricote/releaser-pleaser/internal/forge"
|
||||||
"github.com/apricote/releaser-pleaser/internal/git"
|
"github.com/apricote/releaser-pleaser/internal/git"
|
||||||
|
|
@ -296,6 +296,13 @@ func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (*rele
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GitHub) CreatePullRequest(ctx context.Context, pr *releasepr.ReleasePullRequest) error {
|
func (g *GitHub) CreatePullRequest(ctx context.Context, pr *releasepr.ReleasePullRequest) error {
|
||||||
|
// If the Pull Request is created without the labels releaser-pleaser will create a new PR in the run. The user may merge both and have duplicate entries in the changelog.
|
||||||
|
// We try to avoid this situation by checking for a cancelled context first, and then running both API calls without passing along any cancellations.
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
|
ctx = context.WithoutCancel(ctx)
|
||||||
|
|
||||||
ghPR, _, err := g.client.PullRequests.Create(
|
ghPR, _, err := g.client.PullRequests.Create(
|
||||||
ctx, g.options.Owner, g.options.Repo,
|
ctx, g.options.Owner, g.options.Repo,
|
||||||
&github.NewPullRequest{
|
&github.NewPullRequest{
|
||||||
|
|
@ -309,7 +316,6 @@ func (g *GitHub) CreatePullRequest(ctx context.Context, pr *releasepr.ReleasePul
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: String ID?
|
|
||||||
pr.ID = ghPR.GetNumber()
|
pr.ID = ghPR.GetNumber()
|
||||||
|
|
||||||
err = g.SetPullRequestLabels(ctx, pr, []releasepr.Label{}, pr.Labels)
|
err = g.SetPullRequestLabels(ctx, pr, []releasepr.Label{}, pr.Labels)
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ import (
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||||
|
|
||||||
"github.com/apricote/releaser-pleaser/internal/updater"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -119,7 +117,7 @@ func (r *Repository) Checkout(_ context.Context, branch string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) UpdateFile(_ context.Context, path string, create bool, updaters []updater.Updater) error {
|
func (r *Repository) UpdateFile(_ context.Context, path string, create bool, updateHook func(string) (string, error)) error {
|
||||||
worktree, err := r.r.Worktree()
|
worktree, err := r.r.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -141,13 +139,9 @@ func (r *Repository) UpdateFile(_ context.Context, path string, create bool, upd
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
updatedContent := string(content)
|
updatedContent, err := updateHook(string(content))
|
||||||
|
if err != nil {
|
||||||
for _, update := range updaters {
|
return fmt.Errorf("failed to run update hook on file %s", path)
|
||||||
updatedContent, err = update(updatedContent)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to run updater on file %s", path)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = file.Truncate(0)
|
err = file.Truncate(0)
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,22 @@ var (
|
||||||
ChangelogUpdaterHeaderRegex = regexp.MustCompile(`^# Changelog\n`)
|
ChangelogUpdaterHeaderRegex = regexp.MustCompile(`^# Changelog\n`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func Changelog(info ReleaseInfo) Updater {
|
func Changelog() Updater {
|
||||||
|
return changelog{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type changelog struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c changelog) Files() []string {
|
||||||
|
return []string{ChangelogFile}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c changelog) CreateNewFiles() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c changelog) Update(info ReleaseInfo) func(content string) (string, error) {
|
||||||
return func(content string) (string, error) {
|
return func(content string) (string, error) {
|
||||||
headerIndex := ChangelogUpdaterHeaderRegex.FindStringIndex(content)
|
headerIndex := ChangelogUpdaterHeaderRegex.FindStringIndex(content)
|
||||||
if headerIndex == nil && len(content) != 0 {
|
if headerIndex == nil && len(content) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,15 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChangelogUpdater_UpdateContent(t *testing.T) {
|
func TestChangelogUpdater_Files(t *testing.T) {
|
||||||
|
assert.Equal(t, []string{"CHANGELOG.md"}, Changelog().Files())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChangelogUpdater_CreateNewFiles(t *testing.T) {
|
||||||
|
assert.True(t, Changelog().CreateNewFiles())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChangelogUpdater_Update(t *testing.T) {
|
||||||
tests := []updaterTestCase{
|
tests := []updaterTestCase{
|
||||||
{
|
{
|
||||||
name: "empty file",
|
name: "empty file",
|
||||||
|
|
@ -54,7 +62,7 @@ func TestChangelogUpdater_UpdateContent(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
runUpdaterTest(t, Changelog, tt)
|
runUpdaterTest(t, Changelog(), tt)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,25 @@ import (
|
||||||
|
|
||||||
var GenericUpdaterSemVerRegex = regexp.MustCompile(`\d+\.\d+\.\d+(-[\w.]+)?(.*x-releaser-pleaser-version)`)
|
var GenericUpdaterSemVerRegex = regexp.MustCompile(`\d+\.\d+\.\d+(-[\w.]+)?(.*x-releaser-pleaser-version)`)
|
||||||
|
|
||||||
func Generic(info ReleaseInfo) Updater {
|
func Generic(files []string) Updater {
|
||||||
|
return generic{
|
||||||
|
files: files,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type generic struct {
|
||||||
|
files []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g generic) Files() []string {
|
||||||
|
return g.files
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g generic) CreateNewFiles() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g generic) Update(info ReleaseInfo) func(content string) (string, error) {
|
||||||
return func(content string) (string, error) {
|
return func(content string) (string, error) {
|
||||||
// We strip the "v" prefix to avoid adding/removing it from the users input.
|
// We strip the "v" prefix to avoid adding/removing it from the users input.
|
||||||
version := strings.TrimPrefix(info.Version, "v")
|
version := strings.TrimPrefix(info.Version, "v")
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,15 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenericUpdater_UpdateContent(t *testing.T) {
|
func TestGenericUpdater_Files(t *testing.T) {
|
||||||
|
assert.Equal(t, []string{"foo.bar", "version.txt"}, Generic([]string{"foo.bar", "version.txt"}).Files())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGenericUpdater_CreateNewFiles(t *testing.T) {
|
||||||
|
assert.False(t, Generic([]string{}).CreateNewFiles())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGenericUpdater_Update(t *testing.T) {
|
||||||
tests := []updaterTestCase{
|
tests := []updaterTestCase{
|
||||||
{
|
{
|
||||||
name: "single line",
|
name: "single line",
|
||||||
|
|
@ -47,7 +55,7 @@ func TestGenericUpdater_UpdateContent(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
runUpdaterTest(t, Generic, tt)
|
runUpdaterTest(t, Generic([]string{"version.txt"}), tt)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
internal/updater/packagejson.go
Normal file
39
internal/updater/packagejson.go
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
package updater
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PackageJson creates an updater that modifies the version field in package.json files
|
||||||
|
func PackageJson() Updater {
|
||||||
|
return packagejson{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type packagejson struct{}
|
||||||
|
|
||||||
|
func (p packagejson) Files() []string {
|
||||||
|
return []string{"package.json"}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p packagejson) CreateNewFiles() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p packagejson) Update(info ReleaseInfo) func(content string) (string, error) {
|
||||||
|
return func(content string) (string, error) {
|
||||||
|
// We strip the "v" prefix to match npm versioning convention
|
||||||
|
version := strings.TrimPrefix(info.Version, "v")
|
||||||
|
|
||||||
|
// Regex to match "version": "..." with flexible whitespace and quote styles
|
||||||
|
versionRegex := regexp.MustCompile(`("version"\s*:\s*)"[^"]*"`)
|
||||||
|
|
||||||
|
// Check if the file contains a version field
|
||||||
|
if !versionRegex.MatchString(content) {
|
||||||
|
return content, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace the version value while preserving the original formatting
|
||||||
|
return versionRegex.ReplaceAllString(content, `${1}"`+version+`"`), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
62
internal/updater/packagejson_test.go
Normal file
62
internal/updater/packagejson_test.go
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
package updater
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPackageJsonUpdater_Files(t *testing.T) {
|
||||||
|
assert.Equal(t, []string{"package.json"}, PackageJson().Files())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPackageJsonUpdater_CreateNewFiles(t *testing.T) {
|
||||||
|
assert.False(t, PackageJson().CreateNewFiles())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPackageJsonUpdater_Update(t *testing.T) {
|
||||||
|
tests := []updaterTestCase{
|
||||||
|
{
|
||||||
|
name: "simple package.json",
|
||||||
|
content: `{"name":"test","version":"1.0.0"}`,
|
||||||
|
info: ReleaseInfo{
|
||||||
|
Version: "v2.0.5",
|
||||||
|
},
|
||||||
|
want: `{"name":"test","version":"2.0.5"}`,
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "complex package.json",
|
||||||
|
content: "{\n \"name\": \"test\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"foo\": \"^1.0.0\"\n }\n}",
|
||||||
|
info: ReleaseInfo{
|
||||||
|
Version: "v2.0.0",
|
||||||
|
},
|
||||||
|
want: "{\n \"name\": \"test\",\n \"version\": \"2.0.0\",\n \"dependencies\": {\n \"foo\": \"^1.0.0\"\n }\n}",
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid json",
|
||||||
|
content: `not json`,
|
||||||
|
info: ReleaseInfo{
|
||||||
|
Version: "v2.0.0",
|
||||||
|
},
|
||||||
|
want: `not json`,
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "json without version",
|
||||||
|
content: `{"name":"test"}`,
|
||||||
|
info: ReleaseInfo{
|
||||||
|
Version: "v2.0.0",
|
||||||
|
},
|
||||||
|
want: `{"name":"test"}`,
|
||||||
|
wantErr: assert.NoError,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
runUpdaterTest(t, PackageJson(), tt)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,11 @@ type ReleaseInfo struct {
|
||||||
ChangelogEntry string
|
ChangelogEntry string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Updater func(string) (string, error)
|
type Updater interface {
|
||||||
|
Files() []string
|
||||||
|
CreateNewFiles() bool
|
||||||
|
Update(info ReleaseInfo) func(content string) (string, error)
|
||||||
|
}
|
||||||
|
|
||||||
type NewUpdater func(ReleaseInfo) Updater
|
type NewUpdater func(ReleaseInfo) Updater
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,10 @@ type updaterTestCase struct {
|
||||||
wantErr assert.ErrorAssertionFunc
|
wantErr assert.ErrorAssertionFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
func runUpdaterTest(t *testing.T, constructor NewUpdater, tt updaterTestCase) {
|
func runUpdaterTest(t *testing.T, u Updater, tt updaterTestCase) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
got, err := constructor(tt.info)(tt.content)
|
got, err := u.Update(tt.info)(tt.content)
|
||||||
if !tt.wantErr(t, err, fmt.Sprintf("Updater(%v, %v)", tt.content, tt.info)) {
|
if !tt.wantErr(t, err, fmt.Sprintf("Updater(%v, %v)", tt.content, tt.info)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
mise.toml
Normal file
25
mise.toml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
[tools]
|
||||||
|
go = "1.25.0"
|
||||||
|
golangci-lint = "v2.4.0"
|
||||||
|
goreleaser = "v2.9.0"
|
||||||
|
mdbook = "v0.4.52" # renovate: datasource=github-releases depName=rust-lang/mdbook
|
||||||
|
ko = "v0.18.0" # renovate: datasource=github-releases depName=ko-build/ko
|
||||||
|
|
||||||
|
[settings]
|
||||||
|
# Experimental features are needed for the Go backend
|
||||||
|
experimental = true
|
||||||
|
|
||||||
|
[tasks.lint]
|
||||||
|
run = "golangci-lint run"
|
||||||
|
|
||||||
|
[tasks.test]
|
||||||
|
run = "go test -v -race ./..."
|
||||||
|
|
||||||
|
[tasks.test-e2e]
|
||||||
|
run = "go test -tags e2e_forgejo -v -race ./test/e2e/forgejo"
|
||||||
|
|
||||||
|
[tasks.e2e-forgejo-start]
|
||||||
|
run = "docker compose --project-directory ./test/e2e/forgejo up -d --wait"
|
||||||
|
|
||||||
|
[tasks.e2e-forgejo-stop]
|
||||||
|
run = "docker compose --project-directory ./test/e2e/forgejo down"
|
||||||
|
|
@ -34,10 +34,10 @@ type ReleaserPleaser struct {
|
||||||
commitParser commitparser.CommitParser
|
commitParser commitparser.CommitParser
|
||||||
versioning versioning.Strategy
|
versioning versioning.Strategy
|
||||||
extraFiles []string
|
extraFiles []string
|
||||||
updaters []updater.NewUpdater
|
updaters []updater.Updater
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(forge forge.Forge, logger *slog.Logger, targetBranch string, commitParser commitparser.CommitParser, versioningStrategy versioning.Strategy, extraFiles []string, updaters []updater.NewUpdater) *ReleaserPleaser {
|
func New(forge forge.Forge, logger *slog.Logger, targetBranch string, commitParser commitparser.CommitParser, versioningStrategy versioning.Strategy, extraFiles []string, updaters []updater.Updater) *ReleaserPleaser {
|
||||||
return &ReleaserPleaser{
|
return &ReleaserPleaser{
|
||||||
forge: forge,
|
forge: forge,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
|
@ -281,16 +281,12 @@ func (rp *ReleaserPleaser) runReconcileReleasePR(ctx context.Context) error {
|
||||||
// Info for updaters
|
// Info for updaters
|
||||||
info := updater.ReleaseInfo{Version: nextVersion, ChangelogEntry: changelogEntry}
|
info := updater.ReleaseInfo{Version: nextVersion, ChangelogEntry: changelogEntry}
|
||||||
|
|
||||||
err = repo.UpdateFile(ctx, updater.ChangelogFile, true, updater.WithInfo(info, updater.Changelog))
|
for _, u := range rp.updaters {
|
||||||
if err != nil {
|
for _, file := range u.Files() {
|
||||||
return fmt.Errorf("failed to update changelog file: %w", err)
|
err = repo.UpdateFile(ctx, file, u.CreateNewFiles(), u.Update(info))
|
||||||
}
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to run updater %T: %w", u, err)
|
||||||
for _, path := range rp.extraFiles {
|
}
|
||||||
// TODO: Check for missing files
|
|
||||||
err = repo.UpdateFile(ctx, path, false, updater.WithInfo(info, rp.updaters...))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to run file updater: %w", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ spec:
|
||||||
description: "GitLab token for creating and updating release MRs."
|
description: "GitLab token for creating and updating release MRs."
|
||||||
|
|
||||||
extra-files:
|
extra-files:
|
||||||
description: 'List of files that are scanned for version references.'
|
description: 'List of files that are scanned for version references by the generic updater.'
|
||||||
|
default: ""
|
||||||
|
|
||||||
|
updaters:
|
||||||
|
description: "List of updaters that are run. Default updaters can be removed by specifying them as -name. Multiple updaters should be concatenated with a comma. Default Updaters: changelog,generic"
|
||||||
default: ""
|
default: ""
|
||||||
|
|
||||||
stage:
|
stage:
|
||||||
|
|
@ -40,7 +44,7 @@ releaser-pleaser:
|
||||||
resource_group: releaser-pleaser
|
resource_group: releaser-pleaser
|
||||||
|
|
||||||
image:
|
image:
|
||||||
name: ghcr.io/apricote/releaser-pleaser:v0.6.1 # x-releaser-pleaser-version
|
name: ghcr.io/apricote/releaser-pleaser:v0.7.0 # x-releaser-pleaser-version
|
||||||
entrypoint: [ "" ]
|
entrypoint: [ "" ]
|
||||||
variables:
|
variables:
|
||||||
GITLAB_TOKEN: $[[ inputs.token ]]
|
GITLAB_TOKEN: $[[ inputs.token ]]
|
||||||
|
|
@ -49,4 +53,5 @@ releaser-pleaser:
|
||||||
rp run \
|
rp run \
|
||||||
--forge=gitlab \
|
--forge=gitlab \
|
||||||
--branch=$[[ inputs.branch ]] \
|
--branch=$[[ inputs.branch ]] \
|
||||||
--extra-files="$[[ inputs.extra-files ]]"
|
--extra-files="$[[ inputs.extra-files ]]" \
|
||||||
|
--updaters="$[[ inputs.updaters ]]"
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ func (f *TestForge) Init(ctx context.Context, runID string) error {
|
||||||
func (f *TestForge) initUser(ctx context.Context, runID string) error {
|
func (f *TestForge) initUser(ctx context.Context, runID string) error {
|
||||||
f.username = fmt.Sprintf(TestUserNameTemplate, runID)
|
f.username = fmt.Sprintf(TestUserNameTemplate, runID)
|
||||||
|
|
||||||
|
//gosec:disable G204
|
||||||
if output, err := exec.CommandContext(ctx,
|
if output, err := exec.CommandContext(ctx,
|
||||||
"docker", "compose", "exec", "--user=1000", "forgejo",
|
"docker", "compose", "exec", "--user=1000", "forgejo",
|
||||||
"forgejo", "admin", "user", "create",
|
"forgejo", "admin", "user", "create",
|
||||||
|
|
@ -55,6 +56,7 @@ func (f *TestForge) initUser(ctx context.Context, runID string) error {
|
||||||
return fmt.Errorf("failed to create forgejo user: %w", err)
|
return fmt.Errorf("failed to create forgejo user: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//gosec:disable G204
|
||||||
token, err := exec.CommandContext(ctx,
|
token, err := exec.CommandContext(ctx,
|
||||||
"docker", "compose", "exec", "--user=1000", "forgejo",
|
"docker", "compose", "exec", "--user=1000", "forgejo",
|
||||||
"forgejo", "admin", "user", "generate-access-token",
|
"forgejo", "admin", "user", "generate-access-token",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue