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

build: adds tooling for uploading to object storage #673

Merged
merged 8 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
archive:
needs: build
uses: ./.github/workflows/archive.yaml
upload:
needs:
- archive
- package
uses: ./.github/workflows/upload.yaml
secrets: inherit

# Integration Tests
bats:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ jobs:
archive:
needs: build
uses: ./.github/workflows/archive.yaml
upload:
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to do this for PR branches, or is this temporary to test this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a bit of both. If we don't want to save pull-request builds, we can delete it.

needs:
- archive
- package
uses: ./.github/workflows/upload.yaml
secrets: inherit

# Integration Tests
bats:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ jobs:
needs:
- build
uses: ./.github/workflows/archive.yaml
upload:
needs:
- archive
- package
uses: ./.github/workflows/upload.yaml
secrets: inherit
release:
runs-on: ubuntu-latest
needs:
Expand All @@ -32,8 +38,7 @@ jobs:
path: packages
- id: get-prerelease
run: echo "prerelease=$(just pre-release)" >> "$GITHUB_OUTPUT"
- name: Release
uses: softprops/action-gh-release@v1
- uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: ${{ steps.get-prerelease.outputs.prerelease == 'true' }}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Upload
on:
workflow_call:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
tdstein marked this conversation as resolved.
Show resolved Hide resolved
jobs:
upload:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./.github/actions/setup
- uses: actions/download-artifact@v3
with:
name: archives
path: archives
- uses: actions/download-artifact@v3
with:
name: packages
path: packages
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
- run: just upload
32 changes: 28 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

## Quick Start

- [Contributing](#contributing)
- [Quick Start](#quick-start)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Option 1 - Native](#option-1---native)
- [Option 2 - Docker](#option-2---docker)
- [Installing](#installing)
- [Execution](#execution)
- [Testing](#testing)
- [Unit Tests](#unit-tests)
- [Coverage Reporting](#coverage-reporting)
- [Integration Tests](#integration-tests)
- [UI Tests](#ui-tests)
- [Development](#development)
- [Build Tools](#build-tools)
- [Environment Variables](#environment-variables)
- [Behavior in GitHub Actions](#behavior-in-github-actions)
- [Extension Development](#extension-development)
- [Release](#release)
- [Instructions](#instructions)
- [Pre-Releases](#pre-releases)
- [Release Lifecycle](#release-lifecycle)


The get this project up and running on your local machine, execute the following Just commands:

```console
Expand Down Expand Up @@ -106,7 +130,7 @@ When executing commands the following variables are accepted to change behavior.
| MODE | dev | enum | When set to `dev`, development is enabled. All other values disable development mode. |


#### Continuous Integration in GitHub Actions
#### Behavior in GitHub Actions

When running in GitHub Actions, the env variable `CI` is set to `true` by GitHub. When `CI=true`, the defaults for the following values are adjusted.

Expand All @@ -125,6 +149,8 @@ Execute `eval "$(just configure)"` to configure the executable on your current `

## Release

### Instructions

To start a release create a semver compatible tag.

_For this example, we will use the tag `v0.0.dev0`. This tag already exists, so you will not be able run the following commands verbatim._
Expand Down Expand Up @@ -158,9 +184,7 @@ For additional definitions see https://en.wikipedia.org/wiki/Software_release_li

Currently, the following suffix lineage is in use:

## Release Lifecycle

### Key
### Release Lifecycle

- `X`: The major version.
- `Y`: The minor version.
Expand Down
10 changes: 9 additions & 1 deletion build/ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM ubuntu:jammy
FROM ubuntu:jammy

tdstein marked this conversation as resolved.
Show resolved Hide resolved
ARG NODEVERSION=18
RUN \
Expand Down Expand Up @@ -58,3 +58,11 @@ RUN\
&& go env -w GOPATH=/usr/local/go\
# staticcheck is required to for linting Go
&& go install honnef.co/go/tools/cmd/staticcheck@latest

# AWS is required by this project. The build tooling uses it!
ARG AWSARCHIVE=awscli-exe-linux-x86_64.zip
RUN curl -L -O "https://awscli.amazonaws.com/${AWSARCHIVE}" \
&& unzip -q "${AWSARCHIVE}" \
&& rm "${AWSARCHIVE}"\
&& ./aws/install\
&& rm -r ./aws
12 changes: 12 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ default:
just clean
just web
just build
just package
just archive

os:
#!/usr/bin/env bash
Expand Down Expand Up @@ -277,6 +279,14 @@ test *args=("./..."): stub

just _with_docker go test {{ args }} -covermode set -coverprofile=cover.out

# Uploads distributions to object storage. If invoked with `env CI=true` then all architectures supported by the Go toolchain are uploaded.
upload:
#!/usr/bin/env bash
set -eou pipefail
{{ _with_debug }}

just _with_docker ./scripts/upload.bash {{ _cmd }}

# Executes commands in ./web/Justfile. Equivalent to `just web/dist`, but inside of Docker (i.e., just _with_docker web/dist).
web *args:
#!/usr/bin/env bash
Expand Down Expand Up @@ -323,6 +333,8 @@ _with_docker *args:
-e GOCACHE=/work/.cache/go/cache\
-e GOMODCACHE=/work/.cache/go/mod\
-e MODE={{ _mode }}\
--env-file <(env | grep AWS_)\
--env-file <(env | grep GITHUB_)\
--platform {{ _docker_platform }}\
-v "$(pwd)":/work\
-w /work\
Expand Down
18 changes: 18 additions & 0 deletions scripts/get-vscode-extension-path.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${DEBUG:-false}" = true ];
then
set -x
fi

if [ "$#" -ne 2 ]; then
echo "usage: $0 <cmd> <version>"
exit 1
fi

cmd=$1
version=$2

name=$(basename "$cmd")

printf "$(pwd)/packages/%s" "$name-$version.vsix"
tdstein marked this conversation as resolved.
Show resolved Hide resolved
59 changes: 59 additions & 0 deletions scripts/upload.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "${DEBUG:-false}" = true ];
then
set -x
fi

cmd=$1
if [[ -z "$cmd" ]]; then
echo "usage: $0 <cmd>"
exit 1
fi
echo "Command: $cmd" 1>&2

version=$(./scripts/get-version.bash)
echo "Version: $version" 1>&2

name=$(basename "$cmd")
echo "Name: $name" 1>&2

ref="${GITHUB_REF}"
echo "Git Reference: $ref" 1>&2
echo "Git Commit Hash: $(git show-ref --heads --hash "$ref")"
tdstein marked this conversation as resolved.
Show resolved Hide resolved
ref=${ref#"refs/"}

object_path="s3://posit-publisher/$name/releases/$ref"
echo "Object Path: $object_path" 1>&2

platforms=()
while IFS='' read -r line; do platforms+=("$line"); done < <(./scripts/get-platforms.bash)
for platform in "${platforms[@]}"
tdstein marked this conversation as resolved.
Show resolved Hide resolved
do
echo
echo "Release: $platform" 1>&2
os=${platform/\/*} # retain the part before the slash
arch=${platform/*\/} # retain the part after the slash
archive=$(./scripts/get-archive-path.bash "$name" "$version" "$os" "$arch" )
echo "Archive: $archive" 1>&2
if ! [ -f "$archive" ];
then
echo "Not Found. Skipping..." 1>&2
else
object="$object_path/$(basename "$archive")"
echo "Object: $object" 1>&2
aws s3 cp "$archive" "$object" > /dev/null 2>&1
fi
done

extension=$(./scripts/get-vscode-extension-path.bash "$name" "$version")
echo
echo "VSCode Extension: $extension"
if ! [ -f "$extension" ];
then
echo "Not Found. Skipping..." 1>&2
else
object="$object_path/$(basename "$extension")"
echo "Object: $object" 1>&2
aws s3 cp "$extension" "$object" > /dev/null 2>&1
fi
Loading