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

Feat: add cainomeup script #23

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
235 changes: 178 additions & 57 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,187 @@
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"
# commit-branch-check:
# name: "Check commit branch"
# runs-on: "ubuntu-latest"
# needs:
# - "crate-info"

# steps:
# - name: "Checkout source code"
# uses: "actions/checkout@v3"
# with:
# fetch-depth: 0

# - name: "Check if commit is on main"
# run: |
# COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }})
# GREP_OUTPUT=$(git log origin/main --format=%H | grep "$COMMIT_HASH")

# if [ -z "$GREP_OUTPUT" ]; then
# echo "Cannot release commits not on the main branch"
# exit 1
# fi

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"
with:
fetch-depth: 0

- name: "Check if commit is on main"
- name: "Check against Cargo.toml"
run: |
COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }})
GREP_OUTPUT=$(git log origin/main --format=%H | grep "$COMMIT_HASH")
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$")

if [ -z "$GREP_OUTPUT" ]; then
echo "Cannot release commits not on the main branch"
echo "Crate version mismatch"
exit 1
fi

crate-version-check:
name: "Check crate version"
draft-release:
name: "Create draft release"
runs-on: "ubuntu-latest"
needs: ["crate-info"]
needs:
- "crate-info"
- "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"
- "draft-release"
- "crate-version-check"

strategy:
matrix:
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"
uses: "actions/checkout@v3"

- name: "Check against Cargo.toml"
- name: "Setup stable toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
override: true

- name: "Install cross"
run: |
if [ "cainome" != "${{ needs.crate-info.outputs.crate }}" ]; then
CRATE_NAME="${{ needs.crate-info.outputs.crate }}"
cd ./crates/"${CRATE_NAME#*-}"
fi
cargo install --locked --version 0.2.5 cross

GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$")
- name: "Build release"
run: |
cross build --release --target ${{ matrix.target }}

if [ -z "$GREP_OUTPUT" ]; then
echo "Crate version mismatch"
exit 1
fi
- 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: |
ARTIFACT_NAME="cainome-${{ matrix.target }}.${{ matrix.compressed_ext }}"

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}"

build:
name: "Build for ${{ matrix.os }}"
release-apple:
name: "Build for ${{ matrix.target }}"
runs-on: "${{ matrix.os }}"
needs: ["crate-info"]
needs:
- "crate-info"
- "draft-release"
- "crate-version-check"

strategy:
matrix:
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"
include:
- os: "macos-latest"
target: "x86_64-apple-darwin"
exe: "cainome"
- os: "macos-latest"
target: "aarch64-apple-darwin"
exe: "cainome"

steps:
- name: "Checkout source code"
Expand All @@ -92,30 +192,51 @@ jobs:
with:
toolchain: "stable"
profile: "minimal"
target: "${{ matrix.target }}"
override: true

- name: "Build crate"
- name: "Apple M1 setup"
if: ${{ matrix.target == 'aarch64-apple-darwin' }}
run: |
cargo build --package ${{ needs.crate-info.outputs.crate }} --all-targets
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV

# crates-io-release:
# name: "Release to crates.io"
# runs-on: "ubuntu-latest"
- name: "Build release"
run: |
cargo build --release --all-features --target ${{ matrix.target }}

# needs:
# - "crate-info"
# - "commit-branch-check"
# - "crate-version-check"
# - "build"
- name: "Upload artifacts"
uses: "actions/upload-artifact@v3"
with:
name: "cainome-${{ matrix.target }}"
path: "target/${{ matrix.target }}/release/${{ matrix.exe }}"

# steps:
# - name: "Checkout source code"
# uses: "actions/checkout@v3"
- name: "Tar release"
run: |
cd target/${{ matrix.target }}/release/
tar zcvf ./cainome-${{ matrix.target }}.tar.gz ./${{ matrix.exe }}

# - name: "Login to crates.io"
# run: |
# cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
- name: "Publish compressed artifact"
run: |
ARTIFACT_NAME="cainome-${{ matrix.target }}.tar.gz"

# - name: "Public crate"
# run: |
# cargo publish --package ${{ needs.crate-info.outputs.crate }}
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"

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}'
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
Loading