Skip to content

Commit fc597f4

Browse files
authored
fix: Cl/release fixes 2 (#12595)
Please read [contributing guidelines](CONTRIBUTING.md) and remove this line.
1 parent f1ffc67 commit fc597f4

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

.github/workflows/ci3.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
# exclusive with ci3-external.yml: if it is a pull request target only run if it is NOT a fork.
2929
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
30+
environment: ${{ startsWith(github.ref, 'refs/tags/v') && 'master' || '' }}
3031
strategy:
3132
fail-fast: false
3233
matrix:

ci3/aws/ami_update.sh

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ ssh $ssh_args -F build_instance_ssh_config ubuntu@$ip '
4848
mkdir .aws
4949
'
5050

51-
# Copy aws credentials onto machine.
52-
scp -F build_instance_ssh_config $HOME/.aws/build_instance_credentials ubuntu@$ip:.aws/credentials
53-
5451
# Download crs onto machine.
5552
ssh $ssh_args -F build_instance_ssh_config ubuntu@$ip < ../../barretenberg/scripts/download_bb_crs.sh
5653

ci3/aws_request_instance

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PRICE=$(jq -n "$BID_PER_CPU_HOUR*$CPUS*100000 | round / 100000")
5353
launch_spec=$(cat <<EOF
5454
{
5555
"ImageId": "$AMI",
56-
"KeyName": "build-instance",
56+
"KeyName": "${KEY_NAME:-build-instance}",
5757
"SecurityGroupIds": ["sg-0ccd4e5df0dcca0c9"],
5858
"InstanceType": "$INSTANCE_TYPE",
5959
"BlockDeviceMappings": [

ci3/bootstrap_ec2

+20-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ else
4545
instance_name=$(echo -n "$REF_NAME" | head -c 50 | tr -c 'a-zA-Z0-9-' '_')_$arch
4646
fi
4747

48+
if semver check $REF_NAME; then
49+
# Override the public key that aws will load into ~/.ssh/authorized_keys on the launched instance.
50+
# This requires the restricted key only available in release environments.
51+
key_name="super-build-instance"
52+
else
53+
key_name="build-instance"
54+
fi
55+
4856
[ -n "${INSTANCE_POSTFIX:-}" ] && instance_name+="_$INSTANCE_POSTFIX"
4957

5058
echo_header "request build instance"
@@ -60,13 +68,24 @@ if [ -n "$existing_instance" ]; then
6068
fi
6169

6270
# Request new instance.
63-
ip_sir=$(aws_request_instance $instance_name $cores $arch)
71+
ip_sir=$(KEY_NAME=$key_name aws_request_instance $instance_name $cores $arch)
6472
IFS=':' read -r -a parts <<< "$ip_sir"
6573
ip="${parts[0]}"
6674
sir="${parts[1]}"
6775
iid="${parts[2]}"
6876
trap on_exit EXIT
6977

78+
# If AWS credentials are not set, try to load them from ~/.aws/build_instance_credentials.
79+
if [ -z "${AWS_ACCESS_KEY_ID:-}" ] || [ -z "${AWS_SECRET_ACCESS_KEY:-}" ]; then
80+
if [ ! -f ~/.aws/build_instance_credentials ]; then
81+
echo "No aws credentials found in env or ~/.aws/build_instance_credentials."
82+
exit 1
83+
fi
84+
echo "AWS credentials are being set from ~/.aws/build_instance_credentials."
85+
export AWS_ACCESS_KEY_ID=$(grep aws_access_key_id ~/.aws/build_instance_credentials | awk '{print $3}')
86+
export AWS_SECRET_ACCESS_KEY=$(grep aws_secret_access_key ~/.aws/build_instance_credentials | awk '{print $3}')
87+
fi
88+
7089
# If we're asking to not terminate the instance automatically, we also don't want to remove the container.
7190
[ "$NO_TERMINATE" -eq 0 ] && docker_args+=" --rm"
7291

ci3/clean_remote_tags

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# Set your GitHub repository info and token if needed
3+
GH_OWNER="aztecprotocol"
4+
GH_REPO="aztec-packages"
5+
6+
# Fetch all releases with pagination
7+
page=1
8+
per_page=100
9+
all_releases=""
10+
11+
while true; do
12+
page_releases=$(curl -s "https://api.github.com/repos/$GH_OWNER/$GH_REPO/releases?per_page=$per_page&page=$page" | jq -r '.[].tag_name')
13+
14+
# Break if no more releases are found
15+
if [ -z "$page_releases" ]; then
16+
break
17+
fi
18+
19+
all_releases="$all_releases $page_releases"
20+
page=$((page + 1))
21+
done
22+
# echo "${all_releases[@]}"
23+
24+
# Create an associative array for fast lookup
25+
declare -A release_tags
26+
for tag in $all_releases; do
27+
release_tags["$tag"]=1
28+
done
29+
30+
# List remote tags and delete those not found in releases
31+
for tag in $(git ls-remote --tags origin | awk '{print $2}' | sed 's|refs/tags/||'); do
32+
if [ -z "${release_tags[$tag]}" ]; then
33+
echo "Deleting remote tag: $tag"
34+
git push --delete origin tag "$tag"
35+
fi
36+
done

0 commit comments

Comments
 (0)