Repository: FuelLabs/fuelup
Pull request #179 (2022-09-07 04:43:55)

refactor index-versions to create each package in isolation
refactor `index-versions.sh` to be able to create packages to a channel in a modular fashion. This is done by extracting some functions that run only once per channel out of the script and into the workflow instead (where there will not be much repetition anyway, since there's probably only going to be 4 channels max)

This is in preparation for #162 - the idea is that we want to be able to source a list of components, versions and pass them to this script to add the appropriate headers, URLs and hashes to the channel.


Patch:
diff --git a/.github/workflows/publish-nightly-channel.yml b/.github/workflows/publish-nightly-channel.yml
index 3894e062..a04da1e6 100644
--- a/.github/workflows/publish-nightly-channel.yml
+++ b/.github/workflows/publish-nightly-channel.yml
@@ -21,10 +21,21 @@ jobs:
         id: setup
         run: |
             archive_dir=$(date +'%Y/%m/%d')
-            touch channel-fuel-nightly.toml
             mkdir -p ${{ env.NIGHTLY_CHANNEL_DIR }}
-            ./.github/workflows/scripts/index-versions.sh nightly nightly $GITHUB_RUN_ID channel-fuel-nightly.toml
-            cp channel-fuel-nightly.toml ${{ env.NIGHTLY_CHANNEL_DIR }}
+
+            CHANNEL_TOML="channel-fuel-nightly.toml"
+
+            # Create header for channel
+            touch $CHANNEL_TOML
+            echo -e "published_by = \"https://github.com/FuelLabs/fuelup/actions/runs/${GITHUB_RUN_ID}\"\n" >> $CHANNEL_TOML
+
+            ./.github/workflows/scripts/append_package_to_channel.sh forc nightly $CHANNEL_TOML
+            ./.github/workflows/scripts/append_package_to_channel.sh fuel-core nightly $CHANNEL_TOML
+
+            # Remove extra newline at the end
+            truncate -s -1 $CHANNEL_TOML
+
+            cp $CHANNEL_TOML ${{ env.NIGHTLY_CHANNEL_DIR }}
 
             echo "::set-output name=archive_dir::channels/nightly/$archive_dir"
 
diff --git a/.github/workflows/scripts/index-versions.sh b/.github/workflows/scripts/append_package_to_channel.sh
similarity index 80%
rename from .github/workflows/scripts/index-versions.sh
rename to .github/workflows/scripts/append_package_to_channel.sh
index 9b32b1bf..28871afe 100755
--- a/.github/workflows/scripts/index-versions.sh
+++ b/.github/workflows/scripts/append_package_to_channel.sh
@@ -68,22 +68,13 @@ create_pkg_in_channel() {
 }
 
 main() {
-    FORC_LATEST_VERSION=$1
-    FUEL_CORE_LATEST_VERSION=$2
-    GITHUB_RUN_ID=$3
-    CHANNEL_TOML_NAME=$4
-    mv "$CHANNEL_TOML_NAME" channel.tmp.toml
-    # Cleanup tmp and downloaded tars/bin folders
-    trap 'rm channel.tmp.toml *.tar.gz' ERR EXIT
-
-    echo -e "published_by = \"https://github.com/FuelLabs/fuelup/actions/runs/${GITHUB_RUN_ID}\"\n" >>"$CHANNEL_TOML_NAME"
+    COMPONENT=$1
+    VERSION=$2
+    CHANNEL_TOML_NAME=$3
+    trap 'rm *.tar.gz' ERR EXIT
 
-    create_pkg_in_channel forc "${FORC_LATEST_VERSION}" "${CHANNEL_TOML_NAME}"
-    create_pkg_in_channel fuel-core "${FUEL_CORE_LATEST_VERSION}" "${CHANNEL_TOML_NAME}"
+    create_pkg_in_channel "${COMPONENT}" "${VERSION}" "${CHANNEL_TOML_NAME}"
 
-    # remove newline at the end
-    truncate -s -1 "$CHANNEL_TOML_NAME"
-    printf "Done.\n"
     exit 0
 }
 


Test patch:
diff --git a/.github/workflows/test-toolchain-compatibility.yml b/.github/workflows/test-toolchain-compatibility.yml
index ec0f42ca..0e44e2eb 100644
--- a/.github/workflows/test-toolchain-compatibility.yml
+++ b/.github/workflows/test-toolchain-compatibility.yml
@@ -142,14 +142,25 @@ jobs:
               echo published_by=https://github.com/FuelLabs/fuelup/actions/runs/$GITHUB_RUN_ID >> ${{ env.INCOMPATIBLE_DIR }}/$version
             done
 
-      # Run index-versions.sh here which generates the channel TOML file with download links and hashes for forc and fuel-core.
+      # Generate the channel TOML file here and run append_package_to_channel.sh which appends download links and hashes for forc and fuel-core to the channel TOML.
       - name: Prepare channel with compatible versions
         if: ${{ env.LATEST_COMPATIBLE_FORC && env.LATEST_COMPATIBLE_FUEL_CORE }}
         run: |
-            touch channel-fuel-latest.toml
             mkdir -p ${{ env.LATEST_CHANNEL_DIR }}
-            ./.github/workflows/scripts/index-versions.sh ${{ env.LATEST_COMPATIBLE_FORC }} ${{ env.LATEST_COMPATIBLE_FUEL_CORE }} $GITHUB_RUN_ID channel-fuel-latest.toml
-            cp channel-fuel-latest.toml ${{ env.LATEST_CHANNEL_DIR }}
+
+            CHANNEL_TOML="channel-fuel-latest.toml"
+
+            # Create header for channel
+            touch $CHANNEL_TOML
+            echo -e "published_by = \"https://github.com/FuelLabs/fuelup/actions/runs/${GITHUB_RUN_ID}\"\n" >> $CHANNEL_TOML
+
+            ./.github/workflows/scripts/append_package_to_channel.sh forc ${{ env.LATEST_COMPATIBLE_FORC }} $CHANNEL_TOML
+            ./.github/workflows/scripts/append_package_to_channel.sh fuel-core ${{ env.LATEST_COMPATIBLE_FUEL_CORE }} $CHANNEL_TOML
+
+            # Remove extra newline at the end
+            truncate -s -1 $CHANNEL_TOML
+
+            cp $CHANNEL_TOML ${{ env.LATEST_CHANNEL_DIR }}
 
       - name: Deploy latest channel
         if: ${{ env.LATEST_COMPATIBLE_FORC && env.LATEST_COMPATIBLE_FUEL_CORE }}