Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

notify-registry:
if: startsWith(github.ref, 'refs/tags/v')
needs: [release]
runs-on: ubuntu-latest
steps:
# workflow#765: runtime truth-check via plugin verify-capabilities.
- name: Verify capabilities (runtime truth-check)
run: |
Expand All @@ -63,29 +58,24 @@ jobs:
exit 0
fi
"${{ runner.temp }}/wfctl-bin/wfctl" plugin verify-capabilities --binary "$BIN" .
- name: Notify workflow-registry
if: env.GH_TOKEN != ''
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.REGISTRY_PAT }}
repository: GoCodeAlone/workflow-registry
event-type: plugin-release
client-payload: >-
{"plugin": "${{ github.repository }}", "tag": "${{ github.ref_name }}"}
env:
GH_TOKEN: ${{ secrets.REGISTRY_PAT }}
continue-on-error: true

- name: Publish GitHub release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.RELEASES_TOKEN || github.token }}
script: |
const tag = context.ref.replace('refs/tags/', '');
const { owner, repo } = context.repo;
// listReleases returns drafts; getReleaseByTag 404s on drafts. GoReleaser
// creates releases as draft; this step flips them to non-draft post-publish.
const { data: releases } = await github.rest.repos.listReleases({ owner, repo, per_page: 100 });
const release = releases.find(r => r.tag_name === tag);
// GoReleaser creates draft releases; listReleases sees drafts while
// getReleaseByTag can 404. Retry because the release can be
// eventually visible after asset uploads finish.
let release;
for (let attempt = 0; attempt < 12; attempt++) {
const { data: releases } = await github.rest.repos.listReleases({ owner, repo, per_page: 100 });
release = releases.find(r => r.tag_name === tag);
if (release) break;
await new Promise(resolve => setTimeout(resolve, 5000));
}
if (!release) {
throw new Error(`release for tag ${tag} not found in repo listing (latest 100 releases)`);
}
Expand All @@ -97,3 +87,21 @@ jobs:
draft: false,
});
}

notify-registry:
if: startsWith(github.ref, 'refs/tags/v')
needs: [release]
runs-on: ubuntu-latest
steps:
- name: Notify workflow-registry
if: env.GH_TOKEN != ''
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.REGISTRY_PAT }}
repository: GoCodeAlone/workflow-registry
event-type: plugin-release
client-payload: >-
{"plugin": "${{ github.repository }}", "tag": "${{ github.ref_name }}"}
env:
GH_TOKEN: ${{ secrets.REGISTRY_PAT }}
continue-on-error: true
14 changes: 7 additions & 7 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ version: 2

before:
hooks:
- "sh -c 'rm -rf /tmp/release-stage && mkdir -p /tmp/release-stage'"
- "cp plugin.json /tmp/release-stage/plugin.json"
- "cp plugin.contracts.json /tmp/release-stage/plugin.contracts.json"
- "sh -c \"sed -i.bak 's/\\\"version\\\": \\\".*\\\"/\\\"version\\\": \\\"{{ .Version }}\\\"/' /tmp/release-stage/plugin.json && rm -f /tmp/release-stage/plugin.json.bak\""
- "sh -c \"sed -i.bak 's|/releases/download/v[^/]*/|/releases/download/v{{ .Version }}/|g' /tmp/release-stage/plugin.json && rm -f /tmp/release-stage/plugin.json.bak\""
- "go run github.com/GoCodeAlone/workflow/cmd/wfctl@v0.51.7 plugin validate --file /tmp/release-stage/plugin.json --strict-contracts"
- "sh -c 'rm -rf .goreleaser-tmp && mkdir -p .goreleaser-tmp'"
- "cp plugin.json .goreleaser-tmp/plugin.json"
- "cp plugin.contracts.json .goreleaser-tmp/plugin.contracts.json"
- "sh -c \"sed -i.bak 's/\\\"version\\\": \\\".*\\\"/\\\"version\\\": \\\"{{ .Version }}\\\"/' .goreleaser-tmp/plugin.json && rm -f .goreleaser-tmp/plugin.json.bak\""
- "sh -c \"sed -i.bak 's|/releases/download/v[^/]*/|/releases/download/v{{ .Version }}/|g' .goreleaser-tmp/plugin.json && rm -f .goreleaser-tmp/plugin.json.bak\""
- "go run github.com/GoCodeAlone/workflow/cmd/wfctl@v0.51.7 plugin validate --file .goreleaser-tmp/plugin.json --strict-contracts"

builds:
- main: ./cmd/{{ .ProjectName }}
Expand All @@ -27,7 +27,7 @@ archives:
- formats: [tar.gz]
name_template: "{{ .ProjectName }}-{{ .Os }}-{{ .Arch }}"
files:
- src: /tmp/release-stage/plugin.json
- src: .goreleaser-tmp/plugin.json
dst: plugin.json
- plugin.contracts.json

Expand Down
4 changes: 2 additions & 2 deletions internal/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ printf 'validated %s\n' "$file" >> "$VALIDATION_LOG"
if sourceManifest.Version != originalManifest.Version {
t.Fatalf("source manifest version = %q after hooks, want original %q", sourceManifest.Version, originalManifest.Version)
}
manifest := loadPluginManifestFrom(t, filepath.Join(tmp, "dist", "plugin.json"))
manifest := loadPluginManifestFrom(t, filepath.Join(tmp, ".goreleaser-tmp", "plugin.json"))
if manifest.Version != releaseVersion {
t.Fatalf("manifest version = %q, want %q", manifest.Version, releaseVersion)
}
Expand All @@ -299,7 +299,7 @@ printf 'validated %s\n' "$file" >> "$VALIDATION_LOG"
t.Fatalf("download URL %q does not use release version %s", download.URL, releaseVersion)
}
}
if data, err := os.ReadFile(validationLog); err != nil || !strings.Contains(string(data), "validated dist/plugin.json") {
if data, err := os.ReadFile(validationLog); err != nil || !strings.Contains(string(data), "validated .goreleaser-tmp/plugin.json") {
t.Fatalf("strict validation was not invoked; log=%q err=%v", data, err)
}
if _, err := os.Stat(filepath.Join(tmp, "plugin.json.orig")); !os.IsNotExist(err) {
Expand Down
Loading