Skip to content

Commit

Permalink
update: switch assets.yml to use GitHub API for artifact upload
Browse files Browse the repository at this point in the history
Previous action for uploading artifacts to GitHub Releases failed due to
parallel (matrix) execution issues. Replaced it with direct GitHub API
calls to handle uploads.

This change provides more flexibility and control over artifact
management and release handling.

Added a step to generate sha256 checksum for the rootfs.img

Signed-off-by: yash-zededa <yash@zededa.com>
  • Loading branch information
yash-zededa committed Oct 28, 2024
1 parent 8e7e500 commit 6033980
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions .github/workflows/assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,30 @@ on: # yamllint disable-line rule:truthy
type: string

jobs:
create_release:
runs-on: ubuntu-latest
outputs:
release_id: ${{ steps.create_release.outputs.release_id }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create GitHub Release
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
response=$(curl -s -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"tag_name": "${{ inputs.tag_ref }}",
"name": "${{ inputs.tag_ref }}",
"draft": false,
"prerelease": true
}' https://api.github.com/repos/${{ github.repository }}/releases)
release_id=$(echo "$response" | jq -r .id)
upload_url=$(echo "$response" | jq -r .upload_url | sed -e "s/{?name,label}//")
echo "release_id=$release_id" >> "$GITHUB_OUTPUT"
echo "upload_url=$upload_url" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-20.04
strategy:
Expand Down Expand Up @@ -80,19 +104,34 @@ jobs:
docker create --name eve_sources "$EVE_SOURCES" bash
docker export --output assets/collected_sources.tar.gz eve_sources
docker rm eve_sources
- name: Rename files for release
id: rename-files-for-release
- name: Create SHA256 checksum, rename, and upload files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ needs.create_release.outputs.release_id }}
UPLOAD_URL: ${{ needs.create_release.outputs.upload_url }}
ARCH: ${{ env.ARCH }}
run: |
# Create SHA256 checksum for rootfs.img
sha256sum "assets/rootfs.img" | awk '{ print $1 }' > "assets/${ARCH}.rootfs.img.sha256"
# Rename files in assets to include architecture prefix if not already prefixed, then upload each one
for asset in assets/*; do
mv "$asset" "assets/${{ env.ARCH }}.$(basename "$asset")"
base_name=$(basename "$asset")
# Check if the file already has the ARCH prefix
if [[ "$base_name" == ${ARCH}.* ]]; then
new_name="$base_name" # Keep the name as is
else
new_name="${ARCH}.${base_name}" # Add ARCH prefix
mv "$asset" "assets/$new_name" # Rename the file
fi
echo "Uploading assets/$new_name as $new_name..."
upload_response=$(curl -s -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"assets/$new_name" \
"$UPLOAD_URL?name=$new_name")
if echo "$upload_response" | jq -e .id > /dev/null; then
echo "$new_name uploaded successfully."
else
echo "Error uploading $new_name: $upload_response"
fi
done
- name: Upload release files
id: upload-release-files
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ inputs.tag_ref }}
make_latest: false
files: |
assets/${{ env.ARCH }}.*

0 comments on commit 6033980

Please sign in to comment.