-
Notifications
You must be signed in to change notification settings - Fork 1
138 lines (115 loc) · 4.38 KB
/
Copy pathipfs-deploy.yml
File metadata and controls
138 lines (115 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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"