Skip to content

Build and Push to IPFS #291

Build and Push to IPFS

Build and Push to IPFS #291

Workflow file for this run

name: Build and Push to IPFS
on:
workflow_run:
workflows: [CI Gate]
branches: [main]
types: [completed]
push:
tags:
- v*
workflow_dispatch:
permissions:
contents: write
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_sha || github.ref }}
cancel-in-progress: true
env:
BUN_VERSION: 1.3.13
REGISTRY: ghcr.io
jobs:
publish:
name: Publish IPFS Image
runs-on: ubuntu-latest
if: github.event_name != 'workflow_run' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main')
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install dependencies
run: |
bun install --frozen-lockfile
(cd ui && bun install --frozen-lockfile)
(cd solidity && bun install --frozen-lockfile)
- name: Validate production build
run: bun run ui:build:prod
- name: Set image metadata
run: |
IMAGE_NAME="${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')"
if [[ "${GITHUB_EVENT_NAME}" == "workflow_run" || "${GITHUB_REF_NAME}" == "main" ]]; then
VERSION="latest"
else
VERSION="${GITHUB_REF_NAME#v}"
fi
echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITHUB_ENV"
echo "IMAGE_VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "IMAGE_RELEASE_ID=${IMAGE_NAME}:${VERSION}" >> "$GITHUB_ENV"
- name: Build image
run: docker build . --file ui/Dockerfile --build-arg BUN_VERSION="${BUN_VERSION}" --tag "${IMAGE_RELEASE_ID}"
- name: Log in to the Container registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image
run: docker push "${IMAGE_RELEASE_ID}"
- name: Create a reference for IPFS hash
if: github.ref_type == 'tag'
run: |
IPFS_HASH=$(docker run --entrypoint /bin/sh "${IMAGE_RELEASE_ID}" -c 'cat /ipfs_hash.txt')
echo "IPFS_HASH=${IPFS_HASH}" >> "$GITHUB_ENV"
- name: Create a release
if: github.ref_type == 'tag'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RELEASE_NOTE_TEMPLATE=$(cat << EOF
#### IPFS Hash
\`\`\`
$IPFS_HASH
\`\`\`
You can view published versions of Zoltar through any IPFS gateway.
[ipfs://$IPFS_HASH](ipfs://$IPFS_HASH) __(Recommended)__
_requires Brave Browser or IPFS Desktop_
[https://$IPFS_HASH.ipfs.nftstorage.link](https://$IPFS_HASH.ipfs.nftstorage.link)
[https://$IPFS_HASH.ipfs.zoltu.io](https://$IPFS_HASH.ipfs.zoltu.io)
[https://$IPFS_HASH.ipfs.cf-ipfs.com](https://$IPFS_HASH.ipfs.cf-ipfs.com)
[https://$IPFS_HASH.ipfs.w3s.link](https://$IPFS_HASH.ipfs.w3s.link)
EOF
)
PAYLOAD_TEMPLATE=$(cat <<EOF
{
"name": "$GITHUB_REF_NAME",
"tag_name": "$GITHUB_REF_NAME",
"body": $(echo "$RELEASE_NOTE_TEMPLATE" | jq -cRs '@json|fromjson'),
"draft": false,
"generate_release_notes": true
}
EOF
)
REQUEST_DATA=$(echo "$PAYLOAD_TEMPLATE" | jq -c)
RESPONSE=$(curl \
--silent \
--location \
--request POST \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer $GITHUB_TOKEN" \
--header "X-GitHub-Api-Version: 2022-11-28" \
--data "$REQUEST_DATA" \
--write-out "%{http_code}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases"
)
RESPONSE_CODE=${RESPONSE: -3}
RESPONSE_BODY=${RESPONSE//$RESPONSE_CODE/}
if [ "$RESPONSE_CODE" -ne 201 ]; then
ERROR_MESSAGE=$(echo "$RESPONSE_BODY" | jq '.message')
echo "HTTP $RESPONSE_CODE - $ERROR_MESSAGE"
exit 1
fi
echo "Release ($GITHUB_REF_NAME) successfully created"