Skip to content

Commit

Permalink
feat: add cainomeup script
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Mar 16, 2024
1 parent 7ff76e6 commit 692de70
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 44 deletions.
210 changes: 168 additions & 42 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
on:
push:
branches:
- to_be_defined
# tags:
# - "cainome/v*.*.*"
# - "cainome-*/v*.*.*"
tags:
- "v*.*.*"

name: "Release"

jobs:
crate-info:
name: "Extract crate info"
runs-on: "ubuntu-latest"
outputs:
crate: ${{ steps.derive.outputs.crate }}
version: ${{ steps.derive.outputs.version }}

steps:
- id: "derive"
name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
REGEX="^refs\/tags\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "crate=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
# Just in case we accidentally release something not on main.
commit-branch-check:
name: "Check commit branch"
runs-on: "ubuntu-latest"
needs: ["crate-info"]
needs:
- "crate-info"

steps:
- name: "Checkout source code"
Expand All @@ -51,37 +48,74 @@ jobs:
crate-version-check:
name: "Check crate version"
runs-on: "ubuntu-latest"
needs: ["crate-info"]
needs:
- "crate-info"

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Check against Cargo.toml"
run: |
if [ "cainome" != "${{ needs.crate-info.outputs.crate }}" ]; then
CRATE_NAME="${{ needs.crate-info.outputs.crate }}"
cd ./crates/"${CRATE_NAME#*-}"
fi
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$")
if [ -z "$GREP_OUTPUT" ]; then
echo "Crate version mismatch"
exit 1
fi
build:
name: "Build for ${{ matrix.os }}"
draft-release:
name: "Create draft release"
runs-on: "ubuntu-latest"
needs:
- "crate-info"
- "commit-branch-check"
- "crate-version-check"
outputs:
release-id: ${{ steps.create.outputs.id }}

steps:
- id: "create"
name: "Create draft release"
run: |
ID=$(curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-d '{"tag_name":"v${{ needs.crate-info.outputs.version }}","name":"v${{ needs.crate-info.outputs.version }}","draft":true,"generate_release_notes":true}' |
jq ".id")
echo "id=$ID" >> $GITHUB_OUTPUT
release-non-apple:
name: "Build for ${{ matrix.target }}"
runs-on: "${{ matrix.os }}"
needs: ["crate-info"]
needs:
- "crate-info"
- "draft-release"
- "commit-branch-check"
- "crate-version-check"

strategy:
matrix:
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
include:
- os: "ubuntu-latest"
target: "x86_64-unknown-linux-gnu"
exe: "cainome"
compressed_ext: "tar.gz"
- os: "ubuntu-latest"
target: "x86_64-unknown-linux-musl"
exe: "cainome"
compressed_ext: "tar.gz"
- os: "ubuntu-latest"
target: "aarch64-unknown-linux-gnu"
exe: "cainome"
compressed_ext: "tar.gz"
- os: "ubuntu-latest"
target: "aarch64-unknown-linux-musl"
exe: "cainome"
compressed_ext: "tar.gz"
- os: "windows-latest"
target: "x86_64-pc-windows-msvc"
exe: "cainome.exe"
compressed_ext: "zip"

steps:
- name: "Checkout source code"
Expand All @@ -94,28 +128,120 @@ jobs:
profile: "minimal"
override: true

- name: "Build crate"
- name: "Install cross"
run: |
cargo install --locked --version 0.2.5 cross
- name: "Build release"
run: |
cross build --release --target ${{ matrix.target }}
- name: "Upload artifacts"
uses: "actions/upload-artifact@v3"
with:
name: "cainome-${{ matrix.target }}"
path: "target/${{ matrix.target }}/release/${{ matrix.exe }}"

- name: "Tar release"
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release/
tar zcvf ./cainome-${{ matrix.target }}.tar.gz ./${{ matrix.exe }}
- name: "Zip release"
uses: "TheDoctor0/[email protected]"
if: matrix.os == 'windows-latest'
with:
type: "zip"
filename: "cainome-${{ matrix.target }}.zip"
directory: "target/${{ matrix.target }}/release/"
path: "${{ matrix.exe }}"

- name: "Publish compressed artifact"
shell: "bash"
run: |
cargo build --package ${{ needs.crate-info.outputs.crate }} --all-targets
ARTIFACT_NAME="cainome-${{ matrix.target }}.${{ matrix.compressed_ext }}"
# crates-io-release:
# name: "Release to crates.io"
# runs-on: "ubuntu-latest"
curl -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@target/${{ matrix.target }}/release/${ARTIFACT_NAME}"
# needs:
# - "crate-info"
# - "commit-branch-check"
# - "crate-version-check"
# - "build"
release-apple:
name: "Build for ${{ matrix.target }}"
runs-on: "${{ matrix.os }}"
needs:
- "crate-info"
- "draft-release"
- "commit-branch-check"
- "crate-version-check"

# steps:
# - name: "Checkout source code"
# uses: "actions/checkout@v3"
strategy:
matrix:
include:
- os: "macos-latest"
target: "x86_64-apple-darwin"
exe: "cainome"
- os: "macos-latest"
target: "aarch64-apple-darwin"
exe: "cainome"

# - name: "Login to crates.io"
# run: |
# cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Setup stable toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
target: "${{ matrix.target }}"
override: true

- name: "Apple M1 setup"
if: ${{ matrix.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: "Build release"
run: |
cargo build --release --all-features --target ${{ matrix.target }}
- name: "Upload artifacts"
uses: "actions/upload-artifact@v3"
with:
name: "cainome-${{ matrix.target }}"
path: "target/${{ matrix.target }}/release/${{ matrix.exe }}"

- name: "Tar release"
run: |
cd target/${{ matrix.target }}/release/
tar zcvf ./cainome-${{ matrix.target }}.tar.gz ./${{ matrix.exe }}
- name: "Publish compressed artifact"
run: |
ARTIFACT_NAME="cainome-${{ matrix.target }}.tar.gz"
curl -L --fail "https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}/assets?name=${ARTIFACT_NAME}" \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary "@target/${{ matrix.target }}/release/${ARTIFACT_NAME}"
publish-release:
name: "Publish release"
runs-on: "ubuntu-latest"
needs:
- "draft-release"
- "release-non-apple"
- "release-apple"
- "release-docker-multiarch"

steps:
- name: "Publish release"
run: |
curl -L --fail "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${{ needs.draft-release.outputs.release-id }}" \
-X PATCH \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-d '{"draft":false}'
# - name: "Public crate"
# run: |
# cargo publish --package ${{ needs.crate-info.outputs.crate }}
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cainome"
version = "0.2.3"
version = "0.2.5"
edition = "2021"

[workspace]
Expand Down
Loading

0 comments on commit 692de70

Please sign in to comment.