forked from grafana/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.21-alpine3.18 | ||
|
||
COPY . /src | ||
WORKDIR /src | ||
|
||
RUN go build -o /bin/next-release-cycle . | ||
|
||
ENTRYPOINT ["/bin/next-release-cycle"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Next release cycle | ||
description: Determine the next release cycle given an input. | ||
inputs: | ||
branch-name: | ||
description: Branch name of current release cycle. | ||
required: true | ||
outputs: | ||
next-cycle: | ||
description: Next release cycle (formatted as a version number). | ||
runs: | ||
using: 'docker' | ||
image: Dockerfile | ||
args: | ||
- ${{ inputs.branch-name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/grafana/agent/.github/actions/next-release-cycle | ||
|
||
go 1.21.0 | ||
|
||
require ( | ||
github.com/Masterminds/semver/v3 v3.2.1 // indirect | ||
github.com/blang/semver/v4 v4.0.0 // indirect | ||
github.com/coreos/go-semver v0.3.1 // indirect | ||
golang.org/x/mod v0.13.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= | ||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= | ||
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= | ||
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= | ||
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= | ||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= | ||
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= | ||
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strings" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
) | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() error { | ||
if len(os.Args) != 2 { | ||
return fmt.Errorf("usage: next-release-cycle <branch-name>") | ||
} | ||
|
||
branchName := strings.TrimPrefix(os.Args[1], "release-") | ||
log.Println("Determing release cycle after", branchName) | ||
|
||
currentVersion, err := semver.NewVersion(branchName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nextVersion := semver.New( | ||
currentVersion.Major(), | ||
currentVersion.Minor()+1, | ||
0, | ||
"", | ||
"", | ||
) | ||
nextVersionText := "v" + nextVersion.String() | ||
|
||
// Set the next cycle as a variable in the GitHub Actions environment. | ||
if githubOutputFile := os.Getenv("GITHUB_OUTPUT"); githubOutputFile != "" { | ||
setVariable := fmt.Sprintf("next-cycle=%s\n", nextVersionText) | ||
if err := appendFile(githubOutputFile, []byte(setVariable)); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
fmt.Fprintln(os.Stdout, nextVersionText) | ||
return nil | ||
} | ||
|
||
// appendFile appends data to the file named name. If the file doesn't exist, | ||
// an error is returned. | ||
func appendFile(name string, data []byte) error { | ||
f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
_, err = f.Write(data) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Start new release cycle | ||
on: | ||
workflow_dispatch: {} | ||
create: | ||
branches: | ||
- 'release-v*' | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
jobs: | ||
update-file: | ||
if: ${{ startsWith(github.ref, 'refs/heads/release-v')}} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Check out main branch" | ||
uses: "actions/checkout@v4" | ||
with: | ||
ref: main | ||
- name: "Determine new release cycle" | ||
id: next-release-cycle | ||
uses: "./.github/actions/next-release-cycle" | ||
with: | ||
branch-name: ${{ github.ref }} | ||
- name: "Update version file" | ||
run: | | ||
echo -n "${{ steps.next-release-cycle.outputs.next-cycle }}" > tools/gen-versioned-files/agent-version.txt | ||
- name: "Commit and push" | ||
run: | | ||
git config --local user.name "${GITHUB_ACTOR}" | ||
git config --local user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
BRANCH=update-date-$(date +%s) | ||
git checkout -b $BRANCH | ||
git add tools/gen-versioned-files/agent-version.txt | ||
git commit -F - <<EOF | ||
Start release cycle ${{ steps.next-release-cycle.outputs.next-cycle }}. | ||
Triggered by branch ${GITHUB_REF} being created. | ||