-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (118 loc) · 4.6 KB
/
release.yml
File metadata and controls
138 lines (118 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
env:
GONOSUMCHECK: github.com/GoCodeAlone/*
GONOSUMDB: github.com/GoCodeAlone/*
GOPRIVATE: github.com/GoCodeAlone/*
jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
- name: Configure git for private modules
run: git config --global url."https://${{ secrets.RELEASES_TOKEN }}@github.com/".insteadOf "https://github.com/"
- name: Resolve dependencies
run: go mod tidy
- name: Build binaries
run: |
VERSION=${GITHUB_REF#refs/tags/}
declare -a PLATFORMS=("linux/amd64" "linux/arm64" "darwin/amd64" "darwin/arm64")
mkdir -p bin
for platform in "${PLATFORMS[@]}"; do
os="${platform%%/*}"
arch="${platform##*/}"
output="bin/workflow-plugin-slack-${os}-${arch}"
echo "Building ${output}..."
GOOS=${os} GOARCH=${arch} go build -ldflags "-X main.version=${VERSION}" \
-o "${output}" ./cmd/workflow-plugin-slack
done
ls -la bin/
- name: Create release archives
run: |
mkdir -p dist
for binary in bin/workflow-plugin-slack-*; do
name=$(basename "${binary}")
tar -czf "dist/${name}.tar.gz" -C bin "${name}"
sha256sum "dist/${name}.tar.gz" >> dist/checksums.txt
done
cp plugin.json dist/
ls -la dist/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
dist/*.tar.gz
dist/checksums.txt
dist/plugin.json
generate_release_notes: true
draft: false
prerelease: false
- name: Update registry manifest
if: success()
run: |
VERSION="${GITHUB_REF_NAME#v}"
PLUGIN_NAME="${GITHUB_REPOSITORY##*/}"
REGISTRY_NAME="${PLUGIN_NAME#workflow-plugin-}"
BASE_URL="https://github.com/GoCodeAlone/${PLUGIN_NAME}/releases/download/v${VERSION}/${PLUGIN_NAME}"
git clone "https://x-access-token:${REGISTRY_PAT}@github.com/GoCodeAlone/workflow-registry.git" /tmp/workflow-registry
cd /tmp/workflow-registry
MANIFEST="plugins/${REGISTRY_NAME}/manifest.json"
if [[ ! -f "${MANIFEST}" ]]; then
echo "No manifest found at ${MANIFEST}, skipping registry update."
exit 0
fi
jq --arg v "${VERSION}" \
--arg base "${BASE_URL}" \
'.version = $v |
.downloads = [
{os: "linux", arch: "amd64", url: ($base + "-linux-amd64.tar.gz")},
{os: "linux", arch: "arm64", url: ($base + "-linux-arm64.tar.gz")},
{os: "darwin", arch: "amd64", url: ($base + "-darwin-amd64.tar.gz")},
{os: "darwin", arch: "arm64", url: ($base + "-darwin-arm64.tar.gz")}
]' "${MANIFEST}" > tmp.json && mv tmp.json "${MANIFEST}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
BRANCH="auto/sync-${PLUGIN_NAME}-v${VERSION}"
git checkout -b "${BRANCH}"
git add "plugins/${REGISTRY_NAME}/manifest.json"
git commit -m "sync: ${PLUGIN_NAME} v${VERSION}"
git push "https://x-access-token:${REGISTRY_PAT}@github.com/GoCodeAlone/workflow-registry.git" "${BRANCH}"
gh pr create \
--repo GoCodeAlone/workflow-registry \
--head "${BRANCH}" \
--base main \
--title "sync: ${PLUGIN_NAME} v${VERSION}" \
--body "Auto-sync \`${PLUGIN_NAME}\` manifest to v${VERSION}" \
--label "auto-sync" || true
env:
REGISTRY_PAT: ${{ secrets.REGISTRY_PAT }}
GH_TOKEN: ${{ secrets.REGISTRY_PAT }}
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