Skip to content

Commit c2579a7

Browse files
ci: Add release workflow (#165)
Co-authored-by: Michael Lin <[email protected]>
1 parent 1ee0894 commit c2579a7

File tree

8 files changed

+168
-0
lines changed

8 files changed

+168
-0
lines changed

.bazelrc

+3
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ build:ci --config=ubsan
5656

5757
build:dev --config=ci
5858
build:dev --copt="-Og" # For testing against large projects locally
59+
60+
build:release --copt="-O2"
61+
build:release --config=stacktraces

.buildkite/pipeline.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ steps:
1919
exit 1
2020
fi
2121
22+
./tools/lint.sh
23+
2224
bazel build //... --config=ci
2325
2426
# Don't use //... as that will also try to update snapshots

.github/workflows/release-template.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Download the binary for your platform using:
2+
3+
```bash
4+
TAG=TAG_PLACEHOLDER \
5+
OS="$(uname -s | tr '[:upper:]' '[:lower:]')" \
6+
RELEASE_URL="https://github.com/sourcegraph/scip-clang/releases/download/$TAG" \
7+
bash -c 'curl -L "$RELEASE_URL/scip-clang-$(uname -m)-$OS" -o scip-clang' && \
8+
chmod +x scip-clang
9+
```
10+
11+
The `-debug*` binaries are meant for debugging issues (for example, if you run into a crash with `scip-clang`), and are not recommended for general use.

.github/workflows/release.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
workflow_dispatch:
7+
inputs:
8+
revision:
9+
description: 'Tag or revision to build binaries for'
10+
type: string
11+
required: true
12+
create_release:
13+
description: 'Should publish the binary or not'
14+
required: true
15+
default: 'false'
16+
17+
jobs:
18+
build-and-upload-artifacts:
19+
name: 'Build and upload artifacts'
20+
strategy:
21+
matrix:
22+
platform: ['ubuntu-20.04', 'macos-12', 'windows-2022']
23+
config: ['dev', 'release']
24+
runs-on: ${{ matrix.platform }}
25+
env:
26+
TAG: ${{ github.event.ref }}
27+
steps:
28+
- uses: actions/checkout@v3
29+
- name: '🐍 Install Bazelisk'
30+
run: |
31+
if [ "$RUNNER_OS" == "Windows" ]; then
32+
choco install bazelisk
33+
else
34+
sudo npm install -g @bazel/bazelisk
35+
fi
36+
- id: auth
37+
name: '🔓 Authenticate to Google Cloud'
38+
uses: 'google-github-actions/auth@v1'
39+
with:
40+
workload_identity_provider: ${{ secrets.GCP_IDENTITY_PROVIDER }}
41+
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
42+
create_credentials_file: true
43+
- name: '🚧 Build scip-clang'
44+
run: |
45+
echo "build --remote_cache=$CI_BAZEL_REMOTE_CACHE --google_default_credentials" > ci.bazelrc
46+
bazel build //indexer:scip-clang --config="$CONFIG" --execution_log_binary_file=log
47+
env:
48+
CONFIG: ${{ matrix.config }}
49+
CI_BAZEL_REMOTE_CACHE: 'https://storage.googleapis.com/sourcegraph_bazel_cache'
50+
- name: '🔎 Identify OS'
51+
run: echo "OS=$(uname -s | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
52+
- name: '🪵 Upload log'
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: ${{ env.OS }}-${{ matrix.config }}-build-log
56+
path: log
57+
- name: ${{ format('🪄 Rename binary ({0})', matrix.config) }}
58+
run: |
59+
SUFFIX="-dev"
60+
if [ "$CONFIG" == "release" ]; then
61+
SUFFIX=""
62+
fi
63+
outBinaryPath="scip-clang${SUFFIX}-$(uname -m)-$OS"
64+
cp bazel-bin/main/scip-ruby "$outBinaryPath"
65+
echo "outBinaryPath=$outBinaryPath" >> "$GITHUB_ENV"
66+
echo "suffix=$SUFFIX" >> "$GITHUB_ENV"
67+
env:
68+
OS: ${{ env.OS }}
69+
CONFIG: ${{ matrix.config }}
70+
- name: ${{ format('📦 Store binary ({0})', matrix.config) }}
71+
uses: actions/upload-artifact@v3
72+
with:
73+
name: ${{ matrix.platform }}-${{ matrix.config }}-release-artifacts
74+
path: ${{ env.outBinaryPath }}
75+
76+
create-release:
77+
name: 'Create release'
78+
if: github.event_name != 'workflow_dispatch' || inputs.create_release
79+
needs: build-and-upload-artifacts
80+
runs-on: 'ubuntu-20.04'
81+
steps:
82+
- uses: actions/checkout@v3
83+
- name: '📝 Create Release'
84+
run: |
85+
REV="$INPUT_REVISION"
86+
if [ "$TRIGGER" != "workflow_dispatch" ]; then
87+
REV="${GITHUB_REF/refs\/tags\//}"
88+
fi
89+
TEMPLATE="$(< .github/workflows/release-template.md)"
90+
echo "${TEMPLATE//TAG_PLACEHOLDER/$TAG}" > notes
91+
gh release create "$REV" --title "scip-clang $REV" --notes-file notes
92+
env:
93+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+
TRIGGER: ${{ github.event_name }}
95+
INPUT_REVISION: ${{ inputs.revision }}
96+
# Download everything to avoid spelling out the different
97+
# platforms here.
98+
- name: '📥 Download all artifacts'
99+
uses: actions/download-artifact@v3
100+
- name: '📤 Upload artifacts for release'
101+
run: gh release upload "${GITHUB_REF/refs\/tags\//}" ./*-release-artifacts/*
102+
env:
103+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

fetch_deps.bzl

+21
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ def fetch_direct_dependencies():
181181
urls = ["https://github.com/bazelbuild/buildtools/releases/download/6.0.0/buildifier-linux-arm64"],
182182
)
183183

184+
http_archive(
185+
name = "actionlint_darwin_arm64",
186+
build_file = "@scip_clang//third_party:actionlint.BUILD",
187+
sha256 = "5477f8a5a4073ef086525a2512b2bf1201641cd544034ad0c66f329590638242",
188+
urls = ["https://github.com/rhysd/actionlint/releases/download/v1.6.24/actionlint_1.6.24_darwin_arm64.tar.gz"],
189+
)
190+
191+
http_archive(
192+
name = "actionlint_linux_amd64",
193+
build_file = "@scip_clang//third_party:actionlint.BUILD",
194+
sha256 = "3c5818744143a5d6754edd3dcc4c2b32c9dfcdd3bb30e0e108fb5e5c505262d4",
195+
urls = ["https://github.com/rhysd/actionlint/releases/download/v1.6.24/actionlint_1.6.24_linux_amd64.tar.gz"],
196+
)
197+
198+
http_archive(
199+
name = "actionlint_linux_arm64",
200+
build_file = "@scip_clang//third_party:actionlint.BUILD",
201+
sha256 = "93cc9d1f4a01f0658423b41ecf3bd8c17c619003ec683be8bac9264d0361d0d8",
202+
urls = ["https://github.com/rhysd/actionlint/releases/download/v1.6.24/actionlint_1.6.24_linux_arm64.tar.gz"],
203+
)
204+
184205
http_archive(
185206
name = "rules_python",
186207
sha256 = "29a801171f7ca190c543406f9894abf2d483c206e14d6acbd695623662320097",

third_party/BUILD

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
2+
3+
copy_file(
4+
name = "actionlint_exe",
5+
src = select({
6+
"//config:darwin_arm64": "@actionlint_darwin_arm64//:actionlint",
7+
"//config:linux_x86_64": "@actionlint_linux_amd64//:actionlint",
8+
"//config:linux_arm64": "@actionlint_linux_arm64//:actionlint",
9+
}),
10+
out = "actionlint",
11+
allow_symlink = True,
12+
is_executable = True,
13+
visibility = ["//tools:__subpackages__"],
14+
)

third_party/actionlint.BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exports_files(["actionlint"])

tools/lint.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
PROJECT_ROOT="$(dirname "${BASH_SOURCE[0]}")/.."
5+
6+
if [ ! -f "bazel-bin/third_party/actionlint" ]; then
7+
bazel build //third_party:actionlint
8+
fi
9+
10+
(
11+
cd "$PROJECT_ROOT"
12+
git ls-files ".github/workflows/**.yml" | xargs bazel-bin/third_party/actionlint
13+
)

0 commit comments

Comments
 (0)