Skip to content

Commit

Permalink
release workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam McKee committed Dec 20, 2024
1 parent 1013aec commit cba1d17
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 14 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/gh_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release

on:
push:
branches: [ '*' ]
workflow_dispatch:

jobs:

# verify:
# uses: ./.github/workflows/verify.yml

publish-cargo-crates:
runs-on: ubuntu-latest
# needs: verify
steps:
- uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# - uses: swatinem/rust-cache@v2
# - run: cargo install cargo-release
# - run: cargo release --no-confirm -x patch
- id: version
run: |
VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' l3_cli/Cargo.toml)
TAG_NAME="l3_cli-v$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
outputs:
tag_name: ${{ steps.version.outputs.tag_name }}
version: ${{ steps.version.outputs.version }}

create-gh-release:
runs-on: ubuntu-22.04
needs: publish-cargo-crates
steps:
- uses: actions/checkout@v4
- name: Create release
id: create
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
TAG_NAME: ${{ needs.publish-cargo-crates.outputs.tag_name }}
VERSION: ${{ needs.publish-cargo-crates.outputs.version }}
run: |
NOTES=$(cat l3_cli/CHANGELOG.md | awk -v p="## $VERSION" -F":" '$0 ~ p{f=1;next} /## /{f=0} f')
CREATED_RELEASE=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/eighty4/l3/releases \
-f tag_name="$TAG_NAME" \
-f name="CLI v$VERSION" \
-F body="Release notes\n\n$NOTES" \
-F draft=false \
-F prerelease=false \
-F generate_release_notes=false)
echo "release_id=$(echo $CREATED_RELEASE | jq '.id')" >> "$GITHUB_OUTPUT"
echo "upload_hostname=$(echo $CREATED_RELEASE | jq '.upload_url' | cut -d'/' -f3)" >> "$GITHUB_OUTPUT"
outputs:
release_id: ${{ steps.create.outputs.release_id }}
tag_name: ${{ needs.publish-cargo-crates.outputs.tag_name }}
upload_hostname: ${{ steps.create.outputs.upload_hostname }}

upload-gh-asset-linux-and-macos:
needs: create-gh-release
uses: ./.github/workflows/gh_release_upload.yml
with:
release_id: ${{ needs.create-gh-release.outputs.release_id }}
tag_name: ${{ needs.create-gh-release.outputs.tag_name }}
upload_hostname: ${{ needs.create-gh-release.outputs.upload_hostname }}
secrets: inherit

upload-gh-asset-l3-windows:
needs: create-gh-release
uses: ./.github/workflows/gh_release_upload_windows.yml
with:
release_id: ${{ needs.create-gh-release.outputs.release_id }}
tag_name: ${{ needs.create-gh-release.outputs.tag_name }}
upload_hostname: ${{ needs.create-gh-release.outputs.upload_hostname }}
secrets: inherit
61 changes: 61 additions & 0 deletions .github/workflows/gh_release_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Upload Linux/MacOS

on:
workflow_call:
inputs:
release_id:
required: true
type: string
tag_name:
required: true
type: string
upload_hostname:
required: true
type: string

jobs:

upload-gh-asset:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- filename: l3-linux-x86_64
runner: ubuntu-24.04
target: x86_64-unknown-linux-gnu
- filename: l3-linux-aarch64
runner: ubuntu-24.04
target: aarch64-unknown-linux-gnu
apt_package_linker: gcc-aarch64-linux-gnu
- filename: l3-macos-x86_64
runner: macos-latest
target: x86_64-apple-darwin
- filename: l3-macos-aarch64
runner: macos-latest
target: aarch64-apple-darwin
env:
FILENAME: ${{ matrix.filename }}
TARGET: ${{ matrix.target }}
RELEASE_ID: ${{ inputs.release_id }}
UPLOAD_HOSTNAME: ${{ inputs.upload_hostname }}
steps:
- if: ${{ matrix.apt_package_linker }}
run: sudo apt update && sudo apt install ${{ matrix.apt_package_linker }}
- uses: actions/checkout@v4
with:
ref: ${{ inputs.tag_name }}
- run: rustup install stable
- run: rustup target add $TARGET
- name: build
run: cargo build --release --target $TARGET
- name: upload
run: |
curl --fail --silent -L -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: $(file target/$TARGET/release/l3 -b --mime-type)" \
https://$UPLOAD_HOSTNAME/repos/eighty4/l3/releases/$RELEASE_ID/assets?name=$FILENAME \
--data-binary "@target/$TARGET/release/l3"
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
46 changes: 46 additions & 0 deletions .github/workflows/gh_release_upload_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Upload Windows

on:
workflow_call:
inputs:
release_id:
required: true
type: string
tag_name:
required: true
type: string
upload_hostname:
required: true
type: string

jobs:

upload-windows-asset:
runs-on: windows-2022
strategy:
matrix:
include:
- filename: l3-windows-aarch64.exe
target: aarch64-pc-windows-msvc
- filename: l3-windows-x86_64.exe
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
# with:
# ref: ${{ inputs.tag_name }}
- run: rustup install stable
- run: rustup target add ${{ matrix.target }}
- name: build
shell: powershell
run: cargo build -p l3_cli --release --target ${{ matrix.target }}
- name: upload
shell: powershell
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
RELEASE_ID: ${{ inputs.release_id }}
UPLOAD_HOSTNAME: ${{ inputs.upload_hostname }}
run: |
Move-Item -Path target\${{ matrix.target }}\release\l3.exe -Destination ${{ matrix.filename }}
Move-Item -Path .github/workflows/windows_upload_asset.mjs -Destination upload_asset.mjs
npm i @octokit/core
node upload_asset.mjs eighty4 l3 $env:RELEASE_ID ${{ matrix.filename }} application/x-dosexec $env:UPLOAD_HOSTNAME
33 changes: 19 additions & 14 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: l3 CI
name: Verify

on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
workflow_call:
workflow_dispatch:

jobs:
Expand All @@ -21,20 +22,24 @@ jobs:
- run: echo "We're gonna face it"

build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- run: rustup install stable
- name: cargo build
run: cargo build --all-features --release --workspace

examples:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- run: rustup install stable
- name: cargo build
run: |
cargo run --example build_fn
Expand All @@ -45,8 +50,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- run: rustup install stable
- name: cargo fmt
run: cargo fmt --all -v
- run: git diff --exit-code
Expand All @@ -55,22 +59,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- run: rustup install stable
- run: cargo clippy --all -- -D warnings
if: github.ref == 'refs/heads/main'
- run: cargo clippy --all
if: github.ref != 'refs/heads/main'
continue-on-error: true

test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
runs-on: [macos-latest, ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: dtolnay/rust-toolchain@stable
- uses: swatinem/rust-cache@v2
- run: rustup install stable
- name: cargo test
run: cargo test --workspace
32 changes: 32 additions & 0 deletions .github/workflows/windows_upload_asset.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const owner = process.argv[2]
const repo = process.argv[3]
const releaseId = process.argv[4]
const filename = process.argv[5]
const contentType = process.argv[6]
const baseUrl = 'https://' + process.argv[7]

import {Octokit} from '@octokit/core'

const auth = process.env.GH_TOKEN

const url = `POST /repos/${owner}/${repo}/releases/${releaseId}/assets?name=${filename}`

const options = {
baseUrl,
owner,
repo,
release_id: releaseId,
data: '@' + filename,
headers: {
'Accept': 'application/vnd.github+json',
'Content-Type': contentType,
'X-GitHub-Api-Version': '2022-11-28',
},
}

new Octokit({auth}).request(url, options)
.then(() => console.log('finished'))
.catch((e) => {
console.error(e)
process.exit(1)
})

0 comments on commit cba1d17

Please sign in to comment.