From 2a70a3d058ff89f69c02a4242e2fb57d38e37475 Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Wed, 23 Aug 2023 13:31:46 +0200 Subject: [PATCH 1/4] Make brew audit happy by removing version field --- Formula/fe.rb | 1 - scripts/update.sh | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Formula/fe.rb b/Formula/fe.rb index 67811d4..84cb5b0 100644 --- a/Formula/fe.rb +++ b/Formula/fe.rb @@ -1,7 +1,6 @@ class Fe < Formula desc "Compiler for the Fe programming language" homepage "https://github.com/ethereum/fe" - version "0.24.0" if OS.mac? url "https://github.com/ethereum/fe/releases/download/v0.24.0/fe_mac" diff --git a/scripts/update.sh b/scripts/update.sh index 9f4fdb0..814df94 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -17,7 +17,6 @@ sha256_mac=$(curl -Ls "$url_mac" | shasum -a 256 | awk '{print $1}') blueprint="class Fe < Formula desc \"Compiler for the Fe programming language\" homepage \"https://github.com/ethereum/fe\" - version \"${version}\" if OS.mac? url \"https://github.com/ethereum/fe/releases/download/v${version}/fe_mac\" @@ -36,6 +35,7 @@ blueprint="class Fe < Formula bin.install \"fe_amd64\" => \"fe\" end end -end" +end +" echo "$blueprint" \ No newline at end of file From 742047ccaff0fd89fd7b027bde53afe74b075619 Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Wed, 23 Aug 2023 13:32:49 +0200 Subject: [PATCH 2/4] Add a bunch of scripts for version management --- scripts/archive-current-formula.sh | 27 +++++++++++++++++++++++++++ scripts/check-for-update.sh | 19 +++++++++++++++++++ scripts/get-formula-version.sh | 10 ++++++++++ scripts/get-latest-fe-version.sh | 1 + 4 files changed, 57 insertions(+) create mode 100755 scripts/archive-current-formula.sh create mode 100755 scripts/check-for-update.sh create mode 100755 scripts/get-formula-version.sh create mode 100755 scripts/get-latest-fe-version.sh diff --git a/scripts/archive-current-formula.sh b/scripts/archive-current-formula.sh new file mode 100755 index 0000000..030abe9 --- /dev/null +++ b/scripts/archive-current-formula.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Change the working directory to the script's directory +cd $(dirname "$0") || exit + +# Path to the input file +input_file="../Formula/fe.rb" + +# Extract the version from the input file +version=$(grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' "$input_file" | head -n 1 | sed 's/v//') + +# Check if version is not empty +if [ -n "$version" ]; then + # Define the new filename + new_filename="../Formula/fe@${version}.rb" + + # Check if the new filename already exists + if [ -e "$new_filename" ]; then + echo "File '$new_filename' already exists." + else + # Rename the file + mv "$input_file" "$new_filename" + echo "File renamed to '$new_filename'." + fi +else + echo "Version not found in the file." +fi diff --git a/scripts/check-for-update.sh b/scripts/check-for-update.sh new file mode 100755 index 0000000..a25ff40 --- /dev/null +++ b/scripts/check-for-update.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Change the working directory to the script's directory +cd $(dirname "$0") || exit + +# Run the first script to get the latest FE version +latest_version=$(./get-latest-fe-version.sh) + +# Run the second script to get the formula version +formula_version=$(./get-formula-version.sh) + +# Compare the versions +if [ "$latest_version" != "$formula_version" ]; then + echo "Versions differ: Latest version is $latest_version, Formula version is $formula_version" + exit 1 +else + echo "Versions are the same: $latest_version" + exit 0 +fi \ No newline at end of file diff --git a/scripts/get-formula-version.sh b/scripts/get-formula-version.sh new file mode 100755 index 0000000..08d52c5 --- /dev/null +++ b/scripts/get-formula-version.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Change the working directory to the script's directory +cd $(dirname "$0") || exit + +file_path="../Formula/fe.rb" + +# Extract version using grep and awk +version=$(grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' "$file_path" | head -n 1 | sed 's/v//') +echo $version \ No newline at end of file diff --git a/scripts/get-latest-fe-version.sh b/scripts/get-latest-fe-version.sh new file mode 100755 index 0000000..0e61b15 --- /dev/null +++ b/scripts/get-latest-fe-version.sh @@ -0,0 +1 @@ +echo $(curl -s -L -o /dev/null -w %{url_effective} https://github.com/ethereum/fe/releases/latest | sed 's/.*tag\/v//') \ No newline at end of file From 4aac040740b940fe097ad3bdc71e831e9b1da6e6 Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Wed, 23 Aug 2023 13:33:52 +0200 Subject: [PATCH 3/4] Add a CI cron job to check for new releases periodically --- .github/workflows/release.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c18ca3d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: cut new release + +on: + schedule: + - cron: '*/10 * * * *' +jobs: + trigger: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run first script + run: | + ./scripts/check-for-update.sh + id: version_check + continue-on-error: true # This allows the workflow to continue even if the script fails + - name: Run second script if the versions differ + if: steps.version_check.outcome == 'failure' + run: | + ./scripts/archive-current-formula.sh + ./scripts/update.sh > Formula/fe.rb + git config --global user.email "github-actions-bot@example.com" + git config --global user.name "GitHub Actions Bot" + git checkout -b testbranch3 + git add . + git commit -m "Added new Release via GitHub Actions" + git push origin main \ No newline at end of file From c548a75cf70adfefe14ac160e5de44b3633eed2b Mon Sep 17 00:00:00 2001 From: Christoph Burgdorf Date: Fri, 1 Sep 2023 10:50:46 +0200 Subject: [PATCH 4/4] Ensure to not cut garbage release if Github API is down --- .github/workflows/release.yml | 2 -- scripts/check-for-update.sh | 4 ++-- scripts/get-latest-fe-version.sh | 24 +++++++++++++++++++++++- scripts/update.sh | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c18ca3d..bbd8965 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,9 +14,7 @@ jobs: run: | ./scripts/check-for-update.sh id: version_check - continue-on-error: true # This allows the workflow to continue even if the script fails - name: Run second script if the versions differ - if: steps.version_check.outcome == 'failure' run: | ./scripts/archive-current-formula.sh ./scripts/update.sh > Formula/fe.rb diff --git a/scripts/check-for-update.sh b/scripts/check-for-update.sh index a25ff40..0f1186b 100755 --- a/scripts/check-for-update.sh +++ b/scripts/check-for-update.sh @@ -12,8 +12,8 @@ formula_version=$(./get-formula-version.sh) # Compare the versions if [ "$latest_version" != "$formula_version" ]; then echo "Versions differ: Latest version is $latest_version, Formula version is $formula_version" - exit 1 + exit 0 else echo "Versions are the same: $latest_version" - exit 0 + exit 1 fi \ No newline at end of file diff --git a/scripts/get-latest-fe-version.sh b/scripts/get-latest-fe-version.sh index 0e61b15..a2001b2 100755 --- a/scripts/get-latest-fe-version.sh +++ b/scripts/get-latest-fe-version.sh @@ -1 +1,23 @@ -echo $(curl -s -L -o /dev/null -w %{url_effective} https://github.com/ethereum/fe/releases/latest | sed 's/.*tag\/v//') \ No newline at end of file +#!/bin/bash + +# Define your GitHub repository owner and name +repo_owner="ethereum" +repo_name="fe" + +# Make the API request and store the response in a variable +response=$(curl -s "https://api.github.com/repos/$repo_owner/$repo_name/releases/latest") + +# Check if the request was successful (HTTP status code 200) +if [[ $? -eq 0 ]]; then + # Extract the "name" field from the JSON response + name=$(echo "$response" | jq -r ".name") + + # Remove a leading "v" from the name (if present) + name_without_v="${name#v}" + + # Print the modified name + echo $name_without_v +else + echo "Failed to fetch latest release." + exit 1 +fi diff --git a/scripts/update.sh b/scripts/update.sh index 814df94..e240bc2 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -2,7 +2,7 @@ if [ $# -ne 1 ]; then # If the script is invoked without version parameter, it will figure out the latest release automatically - version=$(curl -s -L -o /dev/null -w %{url_effective} https://github.com/ethereum/fe/releases/latest | sed 's/.*tag\/v//') + version=$(./get-latest-fe-version.sh) else version=$1 fi