Skip to content

Commit

Permalink
git release cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pjmagee committed Jun 16, 2024
1 parent 7ddfcc1 commit 7ec9826
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
with:
version: "latest"
verb: call
args: build --directory=./src
args: build --src=./src
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 3 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Build .NET Example
- name: Release
uses: dagger/[email protected]
with:
version: "latest"
verb: call
args: release --directory=./src --tag=env:TAG --token=env:GITHUB_TOKEN
args: release --directory=. --tag=${{ github.ref_name }} --token=env:GITHUB_TOKEN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "Dota2Helper",
"sdk": "go",
"dependencies": [
{
"name": "arc",
"source": "github.com/sagikazarmark/daggerverse/arc@b45dbd7448bb967aca4a538af9ce7f042abf0316"
},
{
"name": "gh",
"source": "github.com/sagikazarmark/daggerverse/gh@b45dbd7448bb967aca4a538af9ce7f042abf0316"
},
{
"name": "arc",
"source": "github.com/sagikazarmark/daggerverse/arc@b45dbd7448bb967aca4a538af9ce7f042abf0316"
}
],
"source": "dagger",
Expand Down
33 changes: 20 additions & 13 deletions dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
"context"
"dagger/dota-2-helper/internal/dagger"
"fmt"
"strings"
)

type Dota2Helper struct{}

func (m *Dota2Helper) Build(ctx context.Context, directory *Directory) (string, error) {
func (m *Dota2Helper) Build(ctx context.Context, src *Directory) (string, error) {
return dag.Container().
From("mcr.microsoft.com/dotnet/sdk:8.0").
WithDirectory("/src", directory, dagger.ContainerWithDirectoryOpts{
WithDirectory("/src", src, dagger.ContainerWithDirectoryOpts{
Exclude: []string{"**/bin/**", "**/obj/**"},
}).
WithWorkdir("/src").
Expand All @@ -35,11 +36,11 @@ func (m *Dota2Helper) Build(ctx context.Context, directory *Directory) (string,
Stdout(ctx)
}

func (m *Dota2Helper) PublishWindows(ctx context.Context, directory *Directory, version string) *dagger.Container {
func (m *Dota2Helper) PublishWindows(ctx context.Context, src *Directory, version string) *dagger.Container {

return dag.Container().
From("mcr.microsoft.com/dotnet/sdk:8.0").
WithDirectory("/src", directory, dagger.ContainerWithDirectoryOpts{
WithDirectory("/src", src, dagger.ContainerWithDirectoryOpts{
Exclude: []string{"**/bin/**", "**/obj/**"},
}).
WithWorkdir("/src").
Expand All @@ -61,29 +62,35 @@ func (m *Dota2Helper) PublishWindows(ctx context.Context, directory *Directory,

func (m *Dota2Helper) Release(
ctx context.Context,
directory *Directory,
git *Directory,
tag string,
token *dagger.Secret) (dagger.Void, error) {
token *dagger.Secret) error {

var title string = ""
published := m.PublishWindows(ctx, directory, tag)
version := strings.TrimPrefix(tag, "v")
published := m.PublishWindows(ctx, git.Directory("src"), version)
assets := published.Directory("/publish")

gh := dag.Gh(dagger.GhOpts{
Token: token,
Repo: "github.com/pjmagee/dota2-helper",
Token: token,
Repo: "github.com/pjmagee/dota2-helper",
Source: git,
})

zip := dag.Arc(dagger.ArcOpts{}).ArchiveDirectory(fmt.Sprintf("Dota2Helper_%s_windows_amd64", tag), assets).Zip()

ghRelease := gh.Release()

return ghRelease.Create(ctx, tag, title, dagger.GhReleaseCreateOpts{
_, err := gh.Release().Create(ctx, tag, "", dagger.GhReleaseCreateOpts{
Target: "main",
Files: []*dagger.File{zip},
Latest: true,
VerifyTag: true,
Draft: true,
GenerateNotes: true,
Token: token,
})

if err != nil {
return err
}

return nil
}

0 comments on commit 7ec9826

Please sign in to comment.