forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (128 loc) · 4.91 KB
/
sg-binary-release.yml
File metadata and controls
145 lines (128 loc) · 4.91 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
139
140
141
142
143
144
145
name: sg-binary-release
on:
push:
branches:
- main
paths:
# Core sg code
- 'dev/sg/**'
- '.github/workflows/sg-binary-release.yml'
# Core sg dependencies
- 'lib/output/**'
- 'lib/errors/**'
- 'lib/group/**'
# Important things sg imports
- 'dev/ci/images/**' # sg ops
- 'internal/database/migration/**' # sg migration
- 'monitoring/**' # sg monitoring
- 'dev/managedservicesplatform/**' # sg msp
# manual release
workflow_dispatch: {}
env:
GOFLAGS: -trimpath
CGO_ENABLED: '1'
jobs:
touch_sg:
if: github.repository == 'sourcegraph/sourcegraph'
name: Touch sourcegraph/sg
runs-on: ubuntu-latest
steps:
- name: checkout-sourcegraph-sg
uses: actions/checkout@v3
with:
repository: sourcegraph/sg
token: ${{ secrets.SG_RELEASE_TOKEN }}
- name: touch-sourcegraph-sg
run: |
today=$(date +'%Y-%m-%d-%H-%M')
sed -i 's/Latest release: .*/Latest release: '"$today"'/' README.md
git config user.name github-actions
git config user.email [email protected]
git add README.md
git commit -m "Update to latest release"
git push
create_release:
name: create-github-release
needs: touch_sg
runs-on: ubuntu-latest
outputs:
release_name: ${{ steps.release.outputs.release_name }}
steps:
- name: create-github-release
id: release
run: |
today=$(date +'%Y-%m-%d-%H-%M')
short_sha=$(echo ${{ github.sha }} | cut -c1-8)
# ATTENTION: release_name is a duplicate from the last step in this
# file, because I can't get workflow outputs to work. If you change
# one, make sure you change the other.
release_name="${today}-${short_sha}"
echo "### sg snapshot release" >> /tmp/release-notes.md
echo "" >> /tmp/release-notes.md
echo "Commit: https://github.com/sourcegraph/sourcegraph/commit/${{github.sha}}" >> /tmp/release-notes.md
gh release delete -R="${repo}" ${release_name} || true
gh release create -R="${repo}" ${release_name} --notes-file /tmp/release-notes.md
echo "::set-output name=release_name::${release_name}"
env:
repo: sourcegraph/sg
GITHUB_TOKEN: ${{ secrets.SG_RELEASE_TOKEN }}
build:
name: build
needs: [create_release]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
arch:
- amd64
- arm64
exclude:
# Compiling for arm64 on Linux requires more work
- os: ubuntu-latest
arch: arm64
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v4
with: { go-version: '1.22' }
- name: Build and upload macOS
if: startsWith(matrix.os, 'macos-') == true
run: |
cd dev/sg
GOARCH=${{ matrix.arch }} go build -o "sg_$(go env GOOS)_${{ matrix.arch }}" -trimpath \
-ldflags "-s -w -X main.BuildCommit=$(git rev-list -1 HEAD .) -X main.ReleaseName=${{ needs.create_release.outputs.release_name }}" .
- name: Build and upload Linux
if: startsWith(matrix.os, 'ubuntu-') == true
run: |
cd dev/sg
GOARCH=${{ matrix.arch }} go build -o "sg_$(go env GOOS)_${{ matrix.arch }}" -trimpath \
-ldflags "-s -w -X main.BuildCommit=$(git rev-list -1 HEAD .) -X main.ReleaseName=${{ needs.create_release.outputs.release_name }}" .
# On certain CI agents, the glibc might not be the right one, so we build a static variant
CGO_ENABLED=0 GOARCH=${{ matrix.arch }} go build -o "sg_$(go env GOOS)_${{ matrix.arch }}_static" -trimpath \
-ldflags "-s -w -X main.BuildCommit=$(git rev-list -1 HEAD .) -X main.ReleaseName=${{ needs.create_release.outputs.release_name }}" .
- name: Upload release asset
run: |
cd dev/sg
release_name="${{ needs.create_release.outputs.release_name }}"
gh release upload -R="${repo}" ${release_name} "sg_$(go env GOOS)_${{ matrix.arch }}"
env:
repo: sourcegraph/sg
GITHUB_TOKEN: ${{ secrets.SG_RELEASE_TOKEN }}
- name: Upload release asset (linux-amd64-static)
if: startswith(matrix.os, 'ubuntu-') == true
run: |
cd dev/sg
release_name="${{ needs.create_release.outputs.release_name }}"
gh release upload -R="${repo}" ${release_name} "sg_$(go env GOOS)_${{ matrix.arch }}_static"
env:
repo: sourcegraph/sg
GITHUB_TOKEN: ${{ secrets.SG_RELEASE_TOKEN }}
report_failure:
needs: build
if: ${{ failure() }}
uses: sourcegraph/sourcegraph/.github/workflows/report-job-failure.yml@main
secrets: inherit