Skip to content

Avoid folders being considered as objects in listing page #29

Avoid folders being considered as objects in listing page

Avoid folders being considered as objects in listing page #29

Workflow file for this run

name: Build and Upload Artifact
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- '.github/**'
env:
CARGO_TERM_COLOR: always
jobs:
release:
runs-on: thevickypedia-lite
permissions:
contents: write
outputs:
release-id: ${{ steps.create-release.outputs.release_id }}
release-tag: ${{ steps.create-release.outputs.release_tag }}
release-flag: ${{ steps.set-release-flag.outputs.release }}
pkg-name: ${{ steps.get-package-info.outputs.pkg_name }}
bin-name: ${{ steps.get-package-info.outputs.bin_name }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Get Package Name
id: get-package-info
run: |
pkg_name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')
echo "Package Name: $pkg_name"
echo "pkg_name=$pkg_name" >> "$GITHUB_OUTPUT"
bin_name=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].targets[] | select(.kind[] == "bin" or .crate_types[] == "bin") | .name')
echo "Bin Name: $bin_name"
echo "bin_name=$bin_name" >> "$GITHUB_OUTPUT"
pkg_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
echo "Package Version: $pkg_version"
echo "pkg_version=$pkg_version" >> $GITHUB_ENV
shell: bash
- name: Set Release Flag # Release flag is set only for a push on main branch
id: set-release-flag
run: |
git pull
if git tag --list | grep "${{ env.pkg_version }}"; then
echo "Version ${{ env.pkg_version }} exists in tags, setting release flag to 'false'"
echo "release=false" >> $GITHUB_ENV
echo "release=false" >> "$GITHUB_OUTPUT"
else
echo "Version ${{ env.pkg_version }} does not exist in tags, setting release flag to 'true'"
echo "release=true" >> $GITHUB_ENV
echo "release=true" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Create New Release
id: create-release
if: env.release == 'true'
run: |
cargo_prerelease=("alpha" "beta" "rc")
prerelease=false
for cargo_pre in "${cargo_prerelease[@]}"; do
if [[ "${{ env.pkg_version }}" == *"$cargo_pre"* ]]; then
prerelease=true
break
fi
done
echo "Release Tag: ${{ env.pkg_version }}"
latest_tag=$(git tag --list | sort -V | tail -n 1)
if [ -z "$latest_tag" ]; then
lastest_tag=$(curl -s -L https://api.github.com/repos/thevickypedia/lists3/releases/latest | jq -r .tag_name)
fi
commit_msg="**Full Changelog**: ${{ github.server_url }}/${{ github.repository }}/compare/$lastest_tag...${{ env.pkg_version }}"
release_data="{\"tag_name\":\"${{ env.pkg_version }}\",\"name\":\"${{ env.pkg_version }}\",\"body\":\"$commit_msg\",\"draft\":false,\"prerelease\":$prerelease}"
echo "Payload: $release_data"
response=$(curl -X POST -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \
-d "$release_data" \
"https://api.github.com/repos/${{ github.repository }}/releases")
echo "Response: $response"
release_id=$(echo $response | jq -r .id)
if [ "$release_id" = "null" ] || [ -z "$release_id" ]; then
echo "Error: release_id is null. Exiting with code 1."
exit 1
fi
echo "Release ID: $release_id"
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
echo "release_tag=${{ env.pkg_version }}" >> "$GITHUB_OUTPUT"
shell: bash
upload_assets:
needs: release
strategy:
matrix:
platform:
- release_for: Linux-x86_64
os: linux-amd64
bin: ${{ needs.release.outputs.bin-name }}
name: ${{ needs.release.outputs.pkg-name }}-linux-amd64.tar.gz
- release_for: Windows-x86_64
os: windows-amd64
bin: ${{ needs.release.outputs.bin-name }}.exe
name: ${{ needs.release.outputs.pkg-name }}-windows-amd64.zip
- release_for: macOS-x86_64
os: darwin-amd64
bin: ${{ needs.release.outputs.bin-name }}
name: ${{ needs.release.outputs.pkg-name }}-darwin-amd64.tar.gz
- release_for: macOS-arm64
os: darwin-arm64
bin: ${{ needs.release.outputs.bin-name }}
name: ${{ needs.release.outputs.pkg-name }}-darwin-arm64.tar.gz
name: Upload asset for ${{ matrix.platform.release_for }}
if: needs.release.outputs.release-flag == 'true'
runs-on: ${{ matrix.platform.os }}
permissions:
contents: write
steps:
- name: Release ID Propagation
run: |
if [ -n "${{ needs.release.outputs.release-id }}" ]; then
echo "Release ID propagated: ${{ needs.release.outputs.release-id }}"
else
echo "Release ID propagation failed. Exiting.."
exit 1
fi
echo "start_time=$(date +%s)" >> "$GITHUB_ENV"
shell: bash
- name: Checkout Repo
uses: actions/checkout@v4
- name: Update Rust
# print it with style
run: |
printf '*%.0s' {1..60} && printf "\n"
echo "Existing rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n\n"
rustup update && printf "\n"
printf '*%.0s' {1..60} && printf "\n"
echo "Updated rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n"
shell: bash
- name: Build
run: |
cargo build --release
shell: bash
- name: Compress and Copy Artifact (Windows)
if: startsWith(matrix.platform.os, 'windows')
run: |
mkdir -p ${{ needs.release.outputs.pkg-name }}
cp target/release/${{ matrix.platform.bin }} ${{ needs.release.outputs.pkg-name }}/${{ matrix.platform.bin }}
Compress-Archive -DestinationPath ${{ matrix.platform.name }} -Path ${{ needs.release.outputs.pkg-name }}/
shell: pwsh
- name: Compress and Copy Artifact (macOS/Ubuntu)
if: "!startsWith(matrix.platform.os, 'windows')"
run: |
mkdir -p ${{ needs.release.outputs.pkg-name }}
cp target/release/${{ matrix.platform.bin }} ${{ needs.release.outputs.pkg-name }}/${{ matrix.platform.bin }}
tar -zcvf ${{ matrix.platform.name }} ${{ needs.release.outputs.pkg-name }}/
shell: bash
- name: Upload Asset to Release
run: |
curl -X POST -H "Authorization: token ${{ secrets.GIT_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${{ matrix.platform.name }}" \
"https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.release.outputs.release-id }}/assets?name=${{ matrix.platform.name }}"
shell: bash
- name: Runtime Analyzer
run: |
start=${{ env.start_time }}
end=$(date +%s)
time_taken=$((end-start))
url="${{ github.server_url }}/${{ github.repository }}/releases/download/${{ needs.release.outputs.release-tag }}/${{ matrix.platform.name }}"
hyperlink="[${{ matrix.platform.release_for }}]($url)"
echo "🚀 Built for $hyperlink in $time_taken seconds" >> $GITHUB_STEP_SUMMARY
shell: bash
publish-crate:
needs:
- release
- upload_assets
if: needs.release.outputs.release-flag == 'true'
runs-on: thevickypedia-lite
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: |
printf '*%.0s' {1..60} && printf "\n"
echo "Existing rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n\n"
rustup update && printf "\n"
printf '*%.0s' {1..60} && printf "\n"
echo "Updated rust version: $(rustc --version)"
printf '*%.0s' {1..60} && printf "\n"
shell: bash
- name: Release Crate
run: |
cargo login ${{ secrets.CRATES_TOKEN }}
cargo publish --allow-dirty # Set allow-dirty since building will create a /target folder that will be uncommitted in git
shell: bash