Skip to content

Commit bd1d6ca

Browse files
author
Max Pixel
committed
feat(releaser): publish individual component
1 parent 17e113b commit bd1d6ca

2 files changed

Lines changed: 83 additions & 66 deletions

File tree

.github/workflows/publish.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ jobs:
2222
runs-on: ubuntu-latest
2323
steps:
2424
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- name: "Get tags for commit"
28+
id: get-tags
29+
run: |
30+
TAGS=$(git tag --points-at ${{ github.sha }})
31+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
2532
- name: "Publish"
2633
uses: ./.github/actions/call
2734
with:
2835
module: ./releaser
2936
function: |-
3037
publish \
31-
--tag="${{ github.ref_name }}" --commit="${{ github.sha }}" \
38+
--raw-tags="${{ steps.get-tags.outputs.tags }}" --commit="${{ github.sha }}" \
3239
--registry-image="$DAGGER_ENGINE_IMAGE" \
3340
--registry-username="$DAGGER_ENGINE_IMAGE_USERNAME" \
3441
--registry-password=env:DAGGER_ENGINE_IMAGE_PASSWORD \
@@ -90,7 +97,7 @@ jobs:
9097
# TODO: move this into Publish above
9198
daggerverse-bump-dagger:
9299
needs: publish
93-
if: github.ref_name != 'main'
100+
if: ${{ github.repository == 'dagger/dagger' && github.ref_name != 'main' }}
94101
runs-on: dagger-g3-v0-15-4-4c
95102
steps:
96103
- uses: actions/checkout@v4

releaser/main.go

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (report *ReleaseReport) hasErrors() bool {
124124

125125
func (r *Releaser) Publish(
126126
ctx context.Context,
127-
tag string,
127+
rawTags string,
128128
commit string,
129129

130130
dryRun bool, // +optional
@@ -155,71 +155,87 @@ func (r *Releaser) Publish(
155155

156156
discordWebhook *dagger.Secret, // +optional
157157
) (*ReleaseReport, error) {
158+
tags := strings.Fields(rawTags)
159+
componentTags := make(map[string]string)
160+
158161
version := ""
159-
if semver.IsValid(tag) {
160-
version = tag
162+
tag := ""
163+
for _, tagIt := range tags {
164+
finalSlashIndex := strings.LastIndex(tagIt, "/")
165+
if finalSlashIndex != -1 {
166+
componentTag := tagIt[finalSlashIndex+1:]
167+
prefix := tagIt[:finalSlashIndex+1]
168+
componentTags[prefix] = componentTag
169+
} else if semver.IsValid(tagIt) {
170+
version = tagIt
171+
tag = tagIt
172+
} else if version != "" {
173+
tag = tagIt
174+
}
161175
}
176+
162177
report := ReleaseReport{
163178
Date: time.Now().UTC().Format(time.RFC822),
164179
Ref: tag,
165180
Commit: commit,
166181
Version: version,
167182
}
168-
169-
artifact := &ReleaseReportArtifact{
170-
Name: "🚙 Engine",
171-
Tag: tag,
172-
Notify: true,
173-
}
174-
err := r.Dagger.Engine().Publish(ctx, []string{tag, commit}, dagger.DaggerDevDaggerEnginePublishOpts{
175-
Image: registryImage,
176-
RegistryUsername: registryUsername,
177-
RegistryPassword: registryPassword,
178-
DryRun: dryRun,
179-
})
180-
if err != nil {
181-
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
182-
}
183-
report.Artifacts = append(report.Artifacts, artifact)
184-
185-
artifact = &ReleaseReportArtifact{
186-
Name: "🚗 CLI",
187-
Tag: tag,
188-
}
189-
if !dryRun {
190-
err = r.Dagger.Cli().Publish(ctx, tag, githubOrgName, githubToken, goreleaserKey, awsAccessKeyID, awsSecretAccessKey, awsRegion, awsBucket, artefactsFQDN)
191-
if err != nil {
192-
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
183+
if tag != "" {
184+
artifact := &ReleaseReportArtifact{
185+
Name: "🚙 Engine",
186+
Tag: version,
187+
Notify: true,
193188
}
194-
err = r.Dagger.Cli().PublishMetadata(ctx, awsAccessKeyID, awsSecretAccessKey, awsRegion, awsBucket, awsCloudfrontDistribution)
195-
if err != nil {
196-
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
197-
}
198-
} else {
199-
err = r.Dagger.Cli().TestPublish(ctx)
189+
err := r.Dagger.Engine().Publish(ctx, []string{tag, commit}, dagger.DaggerDevDaggerEnginePublishOpts{
190+
Image: registryImage,
191+
RegistryUsername: registryUsername,
192+
RegistryPassword: registryPassword,
193+
DryRun: dryRun,
194+
})
200195
if err != nil {
201196
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
202197
}
203-
}
204-
report.Artifacts = append(report.Artifacts, artifact)
205-
206-
if report.hasErrors() {
207-
// early-exit if engine or cli could not publish
208-
return &report, nil
209-
}
198+
report.Artifacts = append(report.Artifacts, artifact)
210199

211-
if semver.IsValid(version) {
212200
artifact = &ReleaseReportArtifact{
213-
Name: "📖 Docs",
214-
Link: "https://docs.dagger.io",
201+
Name: "🚗 CLI",
202+
Tag: tag,
215203
}
216204
if !dryRun {
217-
err = r.Dagger.Docs().Publish(ctx, netlifyToken)
205+
err = r.Dagger.Cli().Publish(ctx, tag, githubOrgName, githubToken, goreleaserKey, awsAccessKeyID, awsSecretAccessKey, awsRegion, awsBucket, artefactsFQDN)
206+
if err != nil {
207+
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
208+
}
209+
err = r.Dagger.Cli().PublishMetadata(ctx, awsAccessKeyID, awsSecretAccessKey, awsRegion, awsBucket, awsCloudfrontDistribution)
210+
if err != nil {
211+
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
212+
}
213+
} else {
214+
err = r.Dagger.Cli().TestPublish(ctx)
218215
if err != nil {
219216
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
220217
}
221218
}
222219
report.Artifacts = append(report.Artifacts, artifact)
220+
221+
if report.hasErrors() {
222+
// early-exit if engine or cli could not publish
223+
return &report, nil
224+
}
225+
226+
if semver.IsValid(version) {
227+
artifact = &ReleaseReportArtifact{
228+
Name: "📖 Docs",
229+
Link: "https://docs.dagger.io",
230+
}
231+
if !dryRun {
232+
err = r.Dagger.Docs().Publish(ctx, netlifyToken)
233+
if err != nil {
234+
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
235+
}
236+
}
237+
report.Artifacts = append(report.Artifacts, artifact)
238+
}
223239
}
224240

225241
components := []struct {
@@ -322,7 +338,7 @@ func (r *Releaser) Publish(
322338
name: "☸️ Helm Chart",
323339
path: "helm/dagger/",
324340
tag: "helm/chart/",
325-
link: "https://github.com/dagger/dagger/pkgs/container/dagger-helm",
341+
link: "https://github.com/" + githubOrgName + "/dagger/pkgs/container/dagger-helm",
326342
publish: func() error {
327343
return dag.Helm().Publish(ctx, tag, dagger.HelmPublishOpts{
328344
GithubToken: githubToken,
@@ -334,16 +350,12 @@ func (r *Releaser) Publish(
334350
artifacts := make([]*ReleaseReportArtifact, len(components))
335351
var eg errgroup.Group
336352
for i, component := range components {
337-
if component.dev || semver.IsValid(version) {
353+
componentTag, exists := componentTags[component.tag]
354+
if exists && (component.dev || semver.IsValid(componentTag)) {
338355
eg.Go(func() error {
339-
target := ""
340-
if semver.IsValid(version) {
341-
target = strings.TrimSuffix(component.tag, "/") + "/" + version
342-
}
343-
344356
artifact := &ReleaseReportArtifact{
345357
Name: component.name,
346-
Tag: target,
358+
Tag: componentTag,
347359
Link: component.link,
348360
Notify: true,
349361
}
@@ -354,12 +366,10 @@ func (r *Releaser) Publish(
354366
return nil
355367
}
356368

357-
if semver.IsValid(version) {
358-
notes := r.changeNotes(component.path, version)
359-
if err := r.githubRelease(ctx, "https://github.com/dagger/dagger", tag, target, notes, githubToken, dryRun); err != nil {
360-
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
361-
return nil
362-
}
369+
notes := r.changeNotes(component.path, version)
370+
if err := r.githubRelease(ctx, "https://github.com/"+githubOrgName+"/dagger", tag, componentTag, notes, githubToken, dryRun); err != nil {
371+
artifact.Errors = append(artifact.Errors, dag.Error(err.Error()))
372+
return nil
363373
}
364374

365375
return nil
@@ -376,15 +386,15 @@ func (r *Releaser) Publish(
376386
report.Artifacts = append(report.Artifacts, artifact)
377387
}
378388

379-
if semver.IsValid(version) {
389+
if tag != "" {
380390
report.FollowUps = append(report.FollowUps, &ReleaseReportFollowUp{
381391
Name: "❄️ Nix",
382-
Link: "https://github.com/dagger/nix",
392+
Link: "https://github.com/" + githubOrgName + "/nix",
383393
})
384394

385395
report.FollowUps = append(report.FollowUps, &ReleaseReportFollowUp{
386396
Name: "🍺 Homebrew Tap",
387-
Link: "https://github.com/dagger/homebrew-tap",
397+
Link: "https://github.com/" + githubOrgName + "/homebrew-tap",
388398
})
389399
report.FollowUps = append(report.FollowUps, &ReleaseReportFollowUp{
390400
Name: "🍺 Homebrew Core",
@@ -393,11 +403,11 @@ func (r *Releaser) Publish(
393403

394404
report.FollowUps = append(report.FollowUps, &ReleaseReportFollowUp{
395405
Name: "🌌 Daggerverse",
396-
Link: "https://github.com/dagger/dagger.io/pulls?q=author%3Adagger-ci+is%3Apr+in%3Atitle+dgvs+" + strings.TrimPrefix(version, "v"),
406+
Link: "https://github.com/" + githubOrgName + "/dagger.io/pulls?q=author%3Adagger-ci+is%3Apr+in%3Atitle+dgvs+" + strings.TrimPrefix(version, "v"),
397407
})
398408
}
399409

400-
if semver.IsValid(version) && discordWebhook != nil {
410+
if tag != "" && discordWebhook != nil {
401411
if err := report.notify(ctx, discordWebhook); err != nil {
402412
report.Errors = append(report.Errors, dag.Error(err.Error()))
403413
}

0 commit comments

Comments
 (0)