Skip to content

Commit

Permalink
Merge pull request #1 from karthik2804/ci/add_release
Browse files Browse the repository at this point in the history
add ci release action
  • Loading branch information
kate-goldenring committed May 11, 2023
2 parents 9390271 + cd49566 commit 226734a
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 15 deletions.
219 changes: 219 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
name: Release
on:
push:
branches:
- main
tags:
- "v*"
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
reset_canary_release:
name: Delete and create Canary Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Fetch tags
run: git fetch origin --tags

- name: 'Check if canary tag exists'
id: canaryExists
shell: bash
run: git show-ref --tags --verify --quiet -- "refs/tags/canary" && echo "::set-output name=canaryExists::0" || echo "::set-output name=canaryExists::1"

- name: Delete canary tag
if: steps.canaryExists.outputs.canaryExists == 0
uses: dev-drprasad/delete-tag-and-release@v0.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: canary

- name: Recreate canary tag and release
uses: ncipollo/release-action@v1.10.0
with:
tag: canary
allowUpdates: true
prerelease: true
body: |
This is a "canary" release of the most recent commits on our main branch. Canary is **not stable**.
It is only intended for developers wishing to try out the latest features in cloud plugin, some of which may not be fully implemented.
build:
name: Build cloud plugin
runs-on: ${{ matrix.config.os }}
needs: reset_canary_release
strategy:
fail-fast: false
matrix:
config:
- {
os: "ubuntu-latest",
arch: "amd64",
wasiSDK: "linux",
extension: "",
buildArgs: "--features openssl/vendored",
target: "",
targetDir: "target/release",
}
- {
os: "ubuntu-latest",
arch: "aarch64",
wasiSDK: "linux",
extension: "",
buildArgs: "--features openssl/vendored --target aarch64-unknown-linux-gnu",
target: "aarch64-unknown-linux-gnu",
targetDir: "target/aarch64-unknown-linux-gnu/release",
}
- {
os: "macos-latest",
arch: "amd64",
wasiSDK: "macos",
extension: "",
buildArgs: "",
target: "",
targetDir: "target/release",
}
- {
os: "macos-latest",
arch: "aarch64",
wasiSDK: "macos",
extension: "",
buildArgs: "--target aarch64-apple-darwin",
target: "aarch64-apple-darwin",
targetDir: "target/aarch64-apple-darwin/release/",
}
- {
os: "windows-latest",
arch: "amd64",
wasiSDK: "",
extension: ".exe",
buildArgs: "",
target: "",
targetDir: "target/release",
}
steps:
- uses: actions/checkout@v3
- name: Install latest Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.68
default: true
target: ${{ matrix.config.target }}

- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi --toolchain 1.68 && rustup target add wasm32-unknown-unknown --toolchain 1.68

- name: set the release version (main)
shell: bash
run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV

- name: set the release version (tag)
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: lowercase the runner OS name
shell: bash
run: |
OS=$(echo "${{ runner.os }}" | tr '[:upper:]' '[:lower:]')
echo "RUNNER_OS=$OS" >> $GITHUB_ENV
- name: setup for cross-compiled linux aarch64 build
if: matrix.config.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt update
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
echo '[target.aarch64-unknown-linux-gnu]' >> ${HOME}/.cargo/config.toml
echo 'linker = "aarch64-linux-gnu-gcc"' >> ${HOME}/.cargo/config.toml
- name: build release
uses: actions-rs/cargo@v1
with:
command: build
args: "--release ${{ matrix.config.buildArgs }}"

- name: Package as plugins tar
shell: bash
run: |
mkdir -v _dist
cp ${{ matrix.config.targetDir }}/cloud-plugin${{ matrix.config.extension }} _dist/cloud${{ matrix.config.extension }}
cp LICENSE _dist/cloud.license
cd _dist
tar czf cloud-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz cloud.license cloud${{ matrix.config.extension }}
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: cloud-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz
path: _dist/cloud-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz

- name: upload binary to Github release
if: startsWith(github.ref, 'refs/tags/v')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: _dist/cloud-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz
tag: ${{ github.ref }}

- name: upload binary to Github release (canary)
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: _dist/cloud-${{ env.RELEASE_VERSION }}-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz
tag: "canary"

checksums_and_manifests:
name: generate checksums and manifest
runs-on: ubuntu-latest
needs: build
steps:

- uses: actions/checkout@v3
- name: set the release version (main)
shell: bash
run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV

- name: set the release version (tag)
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV

- name: download release assets
uses: actions/download-artifact@v3

- name: generate checksums
run: |
ls -lh
sha256sum cloud*.tar.gz/cloud*.tar.gz > checksums-${{ env.RELEASE_VERSION }}.txt
- name: upload checksums to Github release
if: startsWith(github.ref, 'refs/tags/v')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: checksums-${{ env.RELEASE_VERSION }}.txt
tag: ${{ github.ref }}

- name: upload checksums to Github release (canary)
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: checksums-${{ env.RELEASE_VERSION }}.txt
tag: "canary"

- name: create plugin manifest
shell: bash
run: bash .plugin-manifests/generate-manifest.sh ${{ env.RELEASE_VERSION }} checksums-${{ env.RELEASE_VERSION }}.txt > cloud.json

- name: upload plugin manifest to releases
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: cloud.json
tag: ${{ env.RELEASE_VERSION }}
74 changes: 74 additions & 0 deletions .plugin-manifests/generate-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

if [ $# -ne 2 ]; then
echo 1>&2 "Usage: $0 VERSION_STRING CHECKSUM_FILE"
exit 3
fi

[ ! -f "$2" ] && echo -e "The second argument has to be the checksum file\n\n"Usage: $0 VERSION_STRING CHECKSUM_FILE"" && exit 3

# The first argument is the version (either the tag or canary)
# The second argument is the checksum file
SPIN_COMPAT_STRING=$(cat .plugin-manifests/plugin-spin-compat.txt )
VERSION=$1
PLUGIN_BINARY_VERSION_STRING=$1


# If canary release tag with epoch at the end as it is monotonic
if [[ $VERSION == "canary" ]]; then
PLUGIN_VERSION=$(cat ./Cargo.toml | grep version | head -n 1 | awk '{print $3}')
VERSION="${PLUGIN_VERSION//\"}post.$(date +%s)"
PLUGIN_BINARY_VERSION_STRING="canary"
fi

# Gather the checksums

LINUX_ARM=$(cat $2 | grep "linux-aarch64" | awk '{print $1}')
LINUX_AMD=$(cat $2 | grep "linux-amd64" | awk '{print $1}')
MAC_ARM=$(cat $2 | grep "macos-aarch64" | awk '{print $1}')
MAC_AMD=$(cat $2 | grep "macos-amd64" | awk '{print $1}')
WINDOWS_AMD=$(cat $2 | grep "windows-amd64" | awk '{print $1}')

# Dump out the json manifest
cat <<EOF
{
"name": "cloud",
"description": "The Fermyon Cloud Plugin",
"homepage": "https://github.com/fermyon/cloud-plugin",
"version": "${VERSION//v}",
"spinCompatibility": "${SPIN_COMPAT_STRING}",
"license": "Apache-2.0",
"packages": [
{
"os": "linux",
"arch": "amd64",
"url": "https://github.com/fermyon/cloud-plugin/releases/download/${PLUGIN_BINARY_VERSION_STRING}/cloud-${PLUGIN_BINARY_VERSION_STRING}-linux-amd64.tar.gz",
"sha256": "${LINUX_AMD}"
},
{
"os": "linux",
"arch": "aarch64",
"url": "https://github.com/fermyon/cloud-plugin/releases/download/${PLUGIN_BINARY_VERSION_STRING}/cloud-${PLUGIN_BINARY_VERSION_STRING}-linux-aarch64.tar.gz",
"sha256": "${LINUX_ARM}"
},
{
"os": "macos",
"arch": "aarch64",
"url": "https://github.com/fermyon/cloud-plugin/releases/download/${PLUGIN_BINARY_VERSION_STRING}/cloud-${PLUGIN_BINARY_VERSION_STRING}-macos-aarch64.tar.gz",
"sha256": "${MAC_ARM}"
},
{
"os": "macos",
"arch": "amd64",
"url": "https://github.com/fermyon/cloud-plugin/releases/download/${PLUGIN_BINARY_VERSION_STRING}/cloud-${PLUGIN_BINARY_VERSION_STRING}-macos-amd64.tar.gz",
"sha256": "${MAC_AMD}"
},
{
"os": "windows",
"arch": "amd64",
"url": "https://github.com/fermyon/cloud-plugin/releases/download/${PLUGIN_BINARY_VERSION_STRING}/cloud-${PLUGIN_BINARY_VERSION_STRING}-windows-amd64.tar.gz",
"sha256": "${WINDOWS_AMD}"
}
]
}
EOF
1 change: 1 addition & 0 deletions .plugin-manifests/plugin-spin-compat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
>=0.9
31 changes: 16 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ spin-trigger-http = { git = "https://github.com/fermyon/spin" }
tempfile = "3.3.0"
url = "2.3"
uuid = { version = "1.3", features = ["v4"] }

[target.'cfg(target_os = "linux")'.dependencies]
# This needs to be an explicit dependency to enable
# '--features openssl/vendored', which is used for Linux releases.
openssl = { version = "0.10" }

0 comments on commit 226734a

Please sign in to comment.