Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflows: Update build workflow to not rely on curl based upload #3117

Merged
merged 9 commits into from
Aug 12, 2024
66 changes: 66 additions & 0 deletions .github/discord-embed-webhook.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sth new? Unrelated to the upload issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the upload issue is because gcp deprecated its signature mechanism we were relying on in upload_build.sh script. it was also sending out separate build messages for each build to the discord channel instead of grouping them together.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import argparse
import os
import json
import pathlib

from requests import Response
from discord_webhook import DiscordEmbed, DiscordWebhook


GITHUB_CONTEXT_JSON = os.environ.get("GITHUB_CONTEXT_JSON", "{}")
DOWNLOAD_BASE_URL_TEMPLATE = (
"https://build.livepeer.live/go-livepeer/{version}/{filename}"
)


def get_embeds(embed: DiscordEmbed, ref_name: str, checksums: list[str]):
for line in checksums:
_, filename = line.split()
download_url = DOWNLOAD_BASE_URL_TEMPLATE.format(
version=ref_name,
filename=filename,
)
title = filename.lstrip("livepeer-").split(".")[0]
embed.add_embed_field(name=title, value=download_url, inline=False)


def main(args):
checksums = []
github_context = json.loads(GITHUB_CONTEXT_JSON)
head = github_context.get("head", {})
repo = head.get("repo", {})
checksums_file = pathlib.Path("releases") / f"{args.ref_name}_checksums.txt"
commit_url = f'{repo.get("html_url")}/commit/{head.get("sha")}'
checksums = checksums_file.read_text().splitlines()
webhook = DiscordWebhook(
url=args.discord_url,
content=":white_check_mark: Build succeeded for go-livepeer :white_check_mark:",
username="[BOT] Livepeer builder",
)
webhook.add_file(filename=checksums_file.name, file=checksums_file.read_bytes())
embed = DiscordEmbed(
title=head.get("ref"),
description=args.git_commit,
color=2928914,
url=commit_url,
)
embed.add_embed_field(name="Commit SHA", value=head.get("sha"))
embed.set_author(name=args.git_committer)
get_embeds(embed, args.ref_name, checksums)
embed.set_timestamp()
webhook.add_embed(embed)
response: Response = webhook.execute()
# Fail the script if discord returns anything except OK status
assert (
response.ok
), f"Discord webhook failed {response.status_code} {response.content}"


if __name__ == "__main__":
parser = argparse.ArgumentParser("Discord embed content generator for build system")
parser.add_argument("--discord-url", help="Discord webhook URL")
parser.add_argument("--ref-name", help="Tag/branch/commit for current build")
parser.add_argument("--git-commit", help="git commit message")
parser.add_argument("--git-committer", help="git commit author name")
args = parser.parse_args()
main(args)
108 changes: 63 additions & 45 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:
jobs:
linux-build:
name: Build binaries for ${{ matrix.target.GOOS }}-${{ matrix.target.type }}-${{ matrix.target.GOARCH }}
runs-on: ${{ matrix.target.runner }}
runs-on: ubuntu-20.04
container:
image: ${{ matrix.target.container }}
env:
Expand All @@ -26,31 +26,26 @@ jobs:
target:
- GOOS: linux
GOARCH: amd64
runner: ubuntu-20.04
container: ubuntu:20.04
type: cpu

- GOOS: linux
GOARCH: arm64
runner: ubuntu-20.04
container: ubuntu:20.04
type: cpu

- GOOS: linux
GOARCH: amd64
runner: ubuntu-20.04
container: livepeerci/cuda:12.0.0-cudnn8-devel-ubuntu20.04
type: gpu

- GOOS: linux
GOARCH: arm64
runner: ubuntu-20.04
container: livepeerci/cuda:12.0.0-cudnn8-devel-ubuntu20.04
type: gpu

- GOOS: windows
GOARCH: amd64
runner: ubuntu-20.04
container: ubuntu:22.04
type: cpu

Expand Down Expand Up @@ -78,19 +73,14 @@ jobs:
cache: true
cache-dependency-path: go.sum

- name: Cache ffmpeg
id: cache-ffmpeg
uses: actions/cache@v3
with:
path: /home/runner/compiled
key: ${{ runner.os }}-${{ matrix.target.GOOS }}-${{ matrix.target.GOARCH }}-${{ matrix.target.type }}-ffmpeg-${{ hashFiles('**/install_ffmpeg.sh') }}

- name: Set build environment
run: |
echo "GOARCH=${{ matrix.target.GOARCH }}" >> $GITHUB_ENV
echo "GOOS=${{ matrix.target.GOOS }}" >> $GITHUB_ENV
echo "GO_BUILD_DIR=lp-builds/" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=/github/home/compiled/lib/pkgconfig" >> $GITHUB_ENV
echo "LP_BUILD_DIR=livepeer-${{ matrix.target.GOOS }}-${{ matrix.target.GOARCH }}" >> $GITHUB_ENV
mkdir -p lp-builds/ releases/

- name: Set GPU build environment
if: matrix.target.type == 'gpu'
Expand All @@ -99,6 +89,7 @@ jobs:
echo "LIBRARY_PATH=/usr/local/cuda_${{ matrix.target.GOARCH }}/lib64" >> $GITHUB_ENV
echo "CGO_LDFLAGS=-L/usr/local/cuda_${{ matrix.target.GOARCH }}/lib64" >> $GITHUB_ENV
echo "RELEASE_TAG=gpu" >> $GITHUB_ENV
echo "LP_BUILD_DIR=livepeer-${{ matrix.target.GOOS }}-gpu-${{ matrix.target.GOARCH }}" >> $GITHUB_ENV

- name: Install dependencies
run: |
Expand All @@ -120,7 +111,6 @@ jobs:
run: go mod download

- name: Install ffmpeg
if: steps.cache-ffmpeg.outputs.cache-hit != 'true'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why this is being removed since ffmpeg takes a long time to build

also seems unrelated to the rest of the PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cache has not been working forever (screenshot below)

image

i tried fixing it in 3f048d0 (#3117) but that led to the next builds failing to find protoc. no idea why skipping ffmpeg install step leads to failure to find protoc (and we've observed this happen in the past too). would appreciate some insight into fixing the ffmpeg installation script if we can make use of caching there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context - I am not too familiar with the CI build actions myself. The only thing I can think of is there is a v4 update to the action

skipping ffmpeg install step leads to failure to find protoc

weird, maybe it implicitly installs protoc somehow ... but I am not seeing anything obvious in the install script (and my own box doesn't even have it)

run: ./install_ffmpeg.sh

- name: Build binaries
Expand All @@ -130,24 +120,28 @@ jobs:
git config --global --add safe.directory '*'
./ci_env.sh make

- name: Upload build
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
env:
GHA_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
GCLOUD_SECRET: ${{ secrets.GCLOUD_SECRET }}
DISCORD_URL: ${{ secrets.DISCORD_URL }}
run: ./upload_build.sh
- name: Archive binaries for windows
if: matrix.target.GOOS == 'windows'
run: |
mkdir -p "${GO_BUILD_DIR}/${LP_BUILD_DIR}/"
cd "$GO_BUILD_DIR/"
find . -type f -exec mv '{}' "$LP_BUILD_DIR/" \;
zip -9rq "../releases/$LP_BUILD_DIR.zip" ./

- name: Archive binaries
if: matrix.target.GOOS != 'windows'
run: |
mkdir -p "${GO_BUILD_DIR}/${LP_BUILD_DIR}/"
cd "$GO_BUILD_DIR/"
find . -type f -exec mv '{}' "$LP_BUILD_DIR" \;
tar -czvf "../releases/$LP_BUILD_DIR.tar.gz" ./

- name: Upload artifacts for cutting release
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: release-artifacts
name: release-artifacts-${{ matrix.target.GOOS }}-${{ matrix.target.type }}-${{ matrix.target.GOARCH }}
path: releases/

- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev

macos-build:
name: Build binaries for ${{ matrix.target.GOOS }}-${{ matrix.target.GOARCH }}
runs-on: ${{ matrix.target.runner }}
Expand All @@ -161,7 +155,7 @@ jobs:

- GOOS: darwin
GOARCH: arm64
runner: macos-latest
runner: macos-14-xlarge

steps:
- name: Check out code
Expand All @@ -185,6 +179,8 @@ jobs:
echo "GOARCH=${{ matrix.target.GOARCH }}" >> $GITHUB_ENV
echo "GOOS=${{ matrix.target.GOOS }}" >> $GITHUB_ENV
echo "GO_BUILD_DIR=lp-builds/" >> $GITHUB_ENV
echo "LP_BUILD_DIR=livepeer-${{ matrix.target.GOOS }}-${{ matrix.target.GOARCH }}" >> $GITHUB_ENV
mkdir -p lp-builds/ releases/

- name: Cache ffmpeg
id: cache-ffmpeg
Expand Down Expand Up @@ -230,24 +226,20 @@ jobs:
app-notarization-team-id: ${{ secrets.CI_MACOS_NOTARIZATION_TEAM_ID }}
binary-path: "lp-builds/"

- name: Upload build
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
env:
GHA_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref }}
GCLOUD_KEY: ${{ secrets.GCLOUD_KEY }}
GCLOUD_SECRET: ${{ secrets.GCLOUD_SECRET }}
DISCORD_URL: ${{ secrets.DISCORD_URL }}
run: ./upload_build.sh
- name: Archive binaries
if: matrix.platform.name != 'windows'
run: |
mkdir -p "${GO_BUILD_DIR}/${LP_BUILD_DIR}/"
cd "$GO_BUILD_DIR/"
find . -type f -exec mv '{}' "$LP_BUILD_DIR" \;
tar -czvf "../releases/${LP_BUILD_DIR}.tar.gz" .

- name: Upload artifacts for cutting release
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: release-artifacts
name: release-artifacts-${{ matrix.target.GOOS }}-${{ matrix.target.GOARCH }}
path: releases/

- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev

upload:
name: Upload artifacts to google bucket
permissions:
Expand All @@ -258,11 +250,20 @@ jobs:
- macos-build
- linux-build
steps:
- name: Check out code
uses: actions/[email protected]
with:
fetch-depth: 0
# Check https://github.com/livepeer/go-livepeer/pull/1891
# for ref value discussion
ref: ${{ github.event.pull_request.head.sha }}

- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: release-artifacts
pattern: release-artifacts-*
path: releases/
merge-multiple: true

- name: Generate sha256 checksum and gpg signatures for release artifacts
uses: livepeer/action-gh-checksum-and-gpg-sign@latest
Expand All @@ -289,16 +290,33 @@ jobs:

- name: Upload release archives to Google Cloud
id: upload-archives
uses: google-github-actions/upload-cloud-storage@v1
uses: google-github-actions/upload-cloud-storage@v2
with:
path: "releases"
destination: "build.livepeer.live/${{ github.event.repository.name }}/${{ (github.ref_type == 'tag' && github.ref_name) || github.sha }}"
parent: false
process_gcloudignore: false

- name: Upload branch manifest file
id: upload-manifest
uses: google-github-actions/upload-cloud-storage@v1
uses: google-github-actions/upload-cloud-storage@v2
with:
path: ${{ steps.branch-manifest.outputs.manifest-file }}
destination: "build.livepeer.live/${{ github.event.repository.name }}/"
parent: false
process_gcloudignore: false

- name: Trigger discord webhook
Copy link
Contributor

@pwilczynskiclearcode pwilczynskiclearcode Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which Discord channel receives those messages? A comment in code would be nice

shell: bash
env:
GITHUB_CONTEXT_JSON: ${{ toJson(github.event.pull_request) }}
run: |
pip install -U discord-webhook --no-cache-dir
python .github/discord-embed-webhook.py \
--ref-name="${{ (github.ref_type == 'tag' && github.ref_name) || github.sha }}" \
--discord-url="${{ secrets.DISCORD_URL }}" \
--git-commit="$(git log -1 --pretty=format:'%s')" \
--git-committer="$(git log -1 --pretty=format:'%an')"

- name: Notify new build upload
run: curl -X POST https://holy-bread-207a.livepeer.workers.dev
8 changes: 5 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ jobs:
ref: ${{ github.event.workflow_run.head_branch }}

- name: Download artifacts from build stage
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v6
with:
workflow: build.yaml
name: release-artifacts
run_id: ${{ github.event.workflow_run.id }}
name: release-artifacts-.*
name_is_regexp: true
path: releases/

- uses: actions-ecosystem/action-regex-match@v2
Expand All @@ -41,7 +43,7 @@ jobs:
gpg-key-passphrase: ${{ secrets.CI_GPG_SIGNING_PASSPHRASE }}

- name: Release to github
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: ${{ steps.match-tag.outputs.match != '' }}
with:
generate_release_notes: true
Expand Down
Loading
Loading