Skip to content

Commit

Permalink
Upload a release artifact when pushing a tag v*
Browse files Browse the repository at this point in the history
The github actions API doesn't play well with per commit artifacts. For
now we create a release when pushing a tag.

Consuming the per commit artifacts w/o the github actions API is blocked
by this: actions/upload-artifact#50
  • Loading branch information
jerrymarino committed Oct 1, 2020
1 parent d0fc3cb commit 5185482
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 21 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ jobs:
- name: workspace_v2
run: make workspace_v2

# This uploads `xchammer.zip` as an artifact that can be pulled in via the `WORKSPACE`
# 1. Open github.com/your-org/xchammer
# 2. Navigate to Actions
# 3. Navigate to `Artifacts`
# 4. Put `xchammer.zip` into the WORKSPACE
# This uploads `xchammer.zip` as an artifact to github actions
# For issues mentioned here
# https://github.com/actions/upload-artifact/issues/50
# The Github URL can't be used with Bazel directly in an `http_archive`
# At the time of writing the only way to consume it is to:
# - get the release URL with the github actions API which is valid for 1 minute
# - pull the zip from that URL and re-host it: or somehow use it locally.
# - it'd probably be possible to impalement as a github actions repository
# and that's a lot of unwarranted complexity to integrate XCHammer.
#
# See README.md of how to use the artifact with Bazel
make_release:
name: make_release
runs-on: macOS-latest
Expand All @@ -178,5 +184,5 @@ jobs:
echo ::set-env name=BAZEL_BIN::$(readlink bazel-bin)
- uses: actions/upload-artifact@v2
with:
name: xchammer.zip
name: xchammer
path: ${{ env.BAZEL_BIN }}/xchammer_dist_repo.zip
18 changes: 12 additions & 6 deletions .github/workflows/ci_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,17 @@ jobs:
- name: workspace_v2
run: make workspace_v2

# This uploads `xchammer.zip` as an artifact that can be pulled in via the `WORKSPACE`
# 1. Open github.com/your-org/xchammer
# 2. Navigate to Actions
# 3. Navigate to `Artifacts`
# 4. Put `xchammer.zip` into the WORKSPACE
# This uploads `xchammer.zip` as an artifact to github actions
# For issues mentioned here
# https://github.com/actions/upload-artifact/issues/50
# The Github URL can't be used with Bazel directly in an `http_archive`
# At the time of writing the only way to consume it is to:
# - get the release URL with the github actions API which is valid for 1 minute
# - pull the zip from that URL and re-host it: or somehow use it locally.
# - it'd probably be possible to impalement as a github actions repository
# and that's a lot of unwarranted complexity to integrate XCHammer.
#
# See README.md of how to use the artifact with Bazel
make_release:
name: make_release
runs-on: macOS-latest
Expand All @@ -183,5 +189,5 @@ jobs:
echo ::set-env name=BAZEL_BIN::$(readlink bazel-bin)
- uses: actions/upload-artifact@v2
with:
name: xchammer.zip
name: xchammer
path: ${{ env.BAZEL_BIN }}/xchammer_dist_repo.zip
46 changes: 46 additions & 0 deletions .github/workflows/upload_release_artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This workflow cuts a per commit binary release of XCHammer and uploads
# the binary release WORKSPACE for later consumption.
#
# Basically push a tag to github for the commit and this will append the
# release artifact
#
# Ideally we'd create a Bazel consumeable artifact per commit but using github
# actions w/o any other systems it's not so possible
# https://github.com/actions/upload-artifact/issues/50
on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Artifact

jobs:
build:
name: create_release
runs-on: macOS-latest
steps:
- uses: actions/checkout@v2
- name: make_release
run: make release
- name: create_release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
- name: upload_release_asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: bazel-bin/xchammer_dist_repo.zip
asset_name: xchammer.zip
asset_content_type: application/zip


33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,39 @@ First, pull XCHammer into the `WORKSPACE` file:
_Ideally, pull in a release optimized binary build to keep XCHammer's
dependencies, Swift version, Xcode version, compiler flags, Bazel version, and
build time outside of the main iOS/macOS application's WORKSPACE. To easily
achieve this, main github CI worfklows create a binary release artifact for
each commit:_
achieve this, github CI creates a binary release artifact on receiving a new
tag._

```py
# WORKSPACE
# To get the artifact URL per commit:
# - Navigate to the Actions tab on https://github.com/your-org/xchammer
# - Get the URL of `xchammer.zip` e.g.
# https://github.com/pinterest/xchammer/suites/{suite_number}/artifacts/{artifact_number}
# Recommended approach - the CI auto releases when you push a tag matching `v*`
# The release prefix is the _tested_ bazel version, and XCHammer is often
# forwards and backwards compatible
http_archive(
name = "xchammer",
urls = [ "https://github.com/pinterest/xchammer/suites/{suite_number}/artifacts/{artifact_number}" ],
urls = [ "https://github.com/pinterest/xchammer/releases/download/v3.4.1.0/xchammer.zip" ],
)

# Vendor a binary release of xchammer e.g. from a github action `artifact` on a PR
# https://github.com/pinterest/xchammer/pull/262/checks?check_run_id=1195532626
# local_repository(
# name = "xchammer",
# path = "tools/xchammer"
# )

# Pull from source
# git_repository(
# name = "xchammer",
# remote = "https://github.com/pinterest/xchammer.git",
# commit = "[COMMIT_SHA]"
# )
```
_note: for development, `make build` and the `xchammer_dev_repo` target allow a
WORKSPACE to consume XCHammer built out of tree but point to the latest build,
symlinked in `bazel-bin`. It's also possible to use `local_repository` and
override it using `--override_repository=xchammer=/path/to/xchammer`_
symlinked in `bazel-bin`:
`--override_repository=xchammer=/path/to/xchammer/bazel-bin/xchammer_dev_repo`.
It's also possible to use `local_repository` and override it using
`--override_repository=xchammer=/path/to/xchammer`_

Next, create an `xcode_project` target including targets:
```
Expand Down

0 comments on commit 5185482

Please sign in to comment.