Skip to content

Commit a788810

Browse files
committed
Publish scripts.
1 parent 056cf2d commit a788810

7 files changed

Lines changed: 212 additions & 39 deletions

File tree

.github/workflows/node_util.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
name: publish-casper-sidecar-deb
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
push:
9+
tags:
10+
- "v*.*.*"
11+
12+
jobs:
13+
publish_deb:
14+
strategy:
15+
matrix:
16+
include:
17+
- os: ubuntu-20.04
18+
code_name: focal
19+
# - os: ubuntu-22.04
20+
# code_name: jammy
21+
# - os: ubuntu-24.04
22+
# code_name: noble
23+
24+
runs-on: ${{ matrix.os }}
25+
26+
steps:
27+
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v4
31+
with:
32+
role-to-assume: ${{ secrets.AWS_ACCESS_ROLE_REPO }}
33+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
34+
aws-region: ${{ secrets.AWS_ACCESS_REGION_REPO }}
35+
36+
- name: Install deps
37+
run: |
38+
echo "deb http://repo.aptly.info/ squeeze main" | sudo tee -a /etc/apt/sources.list.d/aptly.list
39+
wget -qO - https://www.aptly.info/pubkey.txt | sudo apt-key add -
40+
sudo apt-get update
41+
sudo apt-get install -y aptly=1.4.0
42+
aptly config show
43+
44+
- name: Import GPG key
45+
uses: crazy-max/ghaction-import-gpg@c8bb57c57e8df1be8c73ff3d59deab1dbc00e0d1 #v5.1.0
46+
with:
47+
gpg_private_key: ${{ secrets.APTLY_GPG_KEY }}
48+
passphrase: ${{ secrets.APTLY_GPG_PASS }}
49+
50+
- name: Build deb
51+
run: ./ci/build_deb.sh
52+
53+
- name: Upload binaries to repo
54+
env:
55+
PLUGIN_REPO_NAME: ${{ secrets.AWS_BUCKET_REPO }}
56+
PLUGIN_REGION: ${{ secrets.AWS_ACCESS_REGION_REPO }}
57+
PLUGIN_GPG_KEY: ${{ secrets.APTLY_GPG_KEY }}
58+
PLUGIN_GPG_PASS: ${{ secrets.APTLY_GPG_PASS }}
59+
PLUGIN_ACL: 'private'
60+
PLUGIN_PREFIX: 'releases'
61+
PLUGIN_DEB_PATH: './artifacts'
62+
PLUGIN_OS_CODENAME: ${{ matrix.code_name }}
63+
run: ./ci/publish_deb_to_repo.sh
64+
65+
- name: Invalidate CloudFront cache
66+
run: |
67+
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_REPO }} --paths "/*"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: push-artifacts
3+
permissions:
4+
contents: read
5+
id-token: write
6+
7+
on:
8+
push:
9+
branches:
10+
- dev
11+
- 'feat-**'
12+
- 'release-**'
13+
14+
jobs:
15+
push_artifacts:
16+
strategy:
17+
matrix:
18+
include:
19+
- os: ubuntu-24.04
20+
code_name: noble
21+
22+
runs-on: ${{ matrix.os }}
23+
24+
steps:
25+
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2
26+
27+
# Assign AWS PROD role to get access to production cloudfronts and S3 buckets
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v4
30+
with:
31+
role-to-assume: ${{ secrets.AWS_ACCESS_ROLE_GENESIS }}
32+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
33+
aws-region: ${{ secrets.AWS_ACCESS_REGION_GENESIS }}
34+
35+
36+
- name: Build artifacts
37+
run: ./ci/build_artifacts_for_upload.sh
38+
39+
- name: Upload artifacts to S3
40+
run: aws s3 sync ./artifacts/ s3://${{ secrets.AWS_BUCKET_GENESIS }}/artifacts/casper-node-util/$(git rev-parse HEAD)/
41+
42+
# Required in case of overwrite
43+
- name: Invalidate CloudFront cache
44+
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_GENESIS }} --paths "/artifacts/casper-node-util/$(git rev-parse HEAD)/*"
45+

build_deb.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

ci/build_artifacts_for_upload.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
3+
# This script will build
4+
# - debian package
5+
# - version.json
6+
# in target/artifacts
7+
8+
set -e
9+
10+
if command -v jq >&2; then
11+
echo "jq installed"
12+
else
13+
echo "ERROR: jq is not installed and required"
14+
exit 1
15+
fi
16+
17+
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)"
18+
ARTIFACTS_DIR="$ROOT_DIR/artifacts/"
19+
GIT_HASH=$(git rev-parse HEAD)
20+
BRANCH_NAME=$(git branch --show-current)
21+
SCRIPT_VERSION=$(cat "$ROOT_DIR/VERSION")
22+
23+
echo "Copying debian to artifacts"
24+
./build_deb.sh
25+
26+
echo "Copying script to artifacts"
27+
cp "$ROOT_DIR/casper-node-util/usr/bin/casper-node-util" "$ARTIFACTS_DIR/casper-node-util"
28+
29+
echo "Building version.json"
30+
jq --null-input \
31+
--arg branch "$BRANCH_NAME" \
32+
--arg version "$SIDECAR_VERSION" \
33+
--arg ghash "$GIT_HASH" \
34+
--arg now "$(jq -nr 'now | strftime("%Y-%m-%dT%H:%M:%SZ")')" \
35+
--arg files "$(ls "$ARTIFACTS_DIR" | jq -nRc '[inputs]')" \
36+
'{"branch": $branch, "version": $version, "git-hash": $ghash, "timestamp": $now, "files": $files}' \
37+
> "$ARTIFACTS_DIR/version.json"

ci/build_deb.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
cd ..
4+
mkdir -p artifacts
5+
dpkg-deb --build casper-node-util "./artifacts/casper-node-util-$(cat VERSION).deb"

ci/publish_deb_to_repo.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Verify all variables are present
5+
if [[ -z $PLUGIN_GPG_KEY || -z $PLUGIN_GPG_PASS || -z $PLUGIN_REGION \
6+
|| -z $PLUGIN_REPO_NAME || -z $PLUGIN_ACL || -z $PLUGIN_PREFIX \
7+
|| -z $PLUGIN_DEB_PATH || -z $PLUGIN_OS_CODENAME ]]; then
8+
echo "ERROR: Environment Variable Missing!"
9+
exit 1
10+
fi
11+
12+
# Verify if its the first time publishing. Will need to know later.
13+
# Probably an easier way to do this check :)
14+
EXISTS_RET=$(aws s3 ls s3://"$PLUGIN_REPO_NAME"/releases/dists/ --region "$PLUGIN_REGION" | grep "$PLUGIN_OS_CODENAME") || EXISTS_RET="false"
15+
16+
# Sanity Check for later
17+
if [ "$EXISTS_RET" = "false" ]; then
18+
echo "First time uploading repo!"
19+
else
20+
echo "Repo Exists! Defaulting to publish update..."
21+
fi
22+
23+
### APTLY SECTION
24+
25+
# Move old config file to use in jq query
26+
mv ~/.aptly.conf ~/.aptly.conf.orig
27+
28+
# Inject ENV Variables and save as .aptly.conf
29+
jq --arg region "$PLUGIN_REGION" --arg bucket "$PLUGIN_REPO_NAME" --arg acl "$PLUGIN_ACL" --arg prefix "$PLUGIN_PREFIX" '.S3PublishEndpoints[$bucket] = {"region":$region, "bucket":$bucket, "acl": $acl, "prefix": $prefix}' ~/.aptly.conf.orig > ~/.aptly.conf
30+
31+
# If aptly repo DOESNT exist locally already
32+
if [ ! "$(aptly repo list | grep $PLUGIN_OS_CODENAME)" ]; then
33+
aptly repo create -distribution="$PLUGIN_OS_CODENAME" -component=main "release-$PLUGIN_OS_CODENAME"
34+
fi
35+
36+
# If aptly mirror DOESNT exist locally already
37+
if [ ! "$(aptly mirror list | grep $PLUGIN_OS_CODENAME)" ] && [ ! "$EXISTS_RET" = "false" ] ; then
38+
aptly mirror create -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME" https://"${PLUGIN_REPO_NAME}"/"${PLUGIN_PREFIX}"/ "${PLUGIN_OS_CODENAME}" main
39+
fi
40+
41+
# When it's not the first time uploading.
42+
if [ ! "$EXISTS_RET" = "false" ]; then
43+
aptly mirror update -ignore-signatures "local-repo-$PLUGIN_OS_CODENAME"
44+
# Found an article that said using 'Name' will select all packages for us
45+
aptly repo import "local-repo-$PLUGIN_OS_CODENAME" "release-$PLUGIN_OS_CODENAME" Name
46+
fi
47+
48+
# Add .debs to the local repo
49+
aptly repo add -force-replace "release-$PLUGIN_OS_CODENAME" "$PLUGIN_DEB_PATH"/*.deb
50+
51+
# Publish to S3
52+
if [ ! "$(aptly publish list | grep $PLUGIN_REPO_NAME | grep $PLUGIN_OS_CODENAME)" ]; then
53+
# If the repo is new
54+
aptly publish repo -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "release-$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
55+
else
56+
# If the repo exists
57+
aptly publish update -batch -force-overwrite -passphrase="$PLUGIN_GPG_PASS" "$PLUGIN_OS_CODENAME" s3:"${PLUGIN_REPO_NAME}":
58+
fi

0 commit comments

Comments
 (0)