Skip to content

Commit

Permalink
Fix support for direct download links for local manifests (#47)
Browse files Browse the repository at this point in the history
* Move local manifests command to its own block
Allows better handling of raw xml files

* debug: echo local manifest command

* Try to switch to curl

* Deal with trailing slashes and create folder if it doesn't exist

* Fix github actions syntax error

* Try to seperately wrap the commands inside local manifest

* See if different quotes solve it

* Try to use a here-document

* Adjust here-document

* Adjust spacing

* Try to use one line

* Export the previous variable and fix the rm command

* Fix cat path

* Remove debug line for testing
  • Loading branch information
sounddrill31 authored Aug 4, 2024
1 parent b1837c6 commit a148797
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 71 deletions.
38 changes: 23 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,24 @@ jobs:
LUNCH="breakfast ${{ github.event.inputs.PRODUCT_NAME }} ${{ github.event.inputs.BUILD_TYPE }}"
fi
#copy from here
if [[ "${{ github.event.inputs.LOCAL_MANIFEST }}" =~ \.xml(/)?$ ]]; then
local_manifest_url="${{ github.event.inputs.LOCAL_MANIFEST }}"
export local_manifest_url="${local_manifest_url%/}" # remove trailing slash if it exists
export LOCAL_MANIFEST=$(mkdir -p .repo/local_manifests && rm -rf .repo/local_manifests/* || true && curl -o .repo/local_manifests/local_manifest.xml "${local_manifest_url}")
else
export LOCAL_MANIFEST="git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${github.event.inputs.LOCAL_MANIFEST_BRANCH} local_manifests"
fi
echo "Building on ${{ github.event.inputs.BASE_PROJECT }} project"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_OUTPUT"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_OUTPUT"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_OUTPUT"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_OUTPUT"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_OUTPUT"
- name: Display Run Parameters # Credit to azwhikaru for this part
run: |
echo "::group::User Environment Variables"
Expand All @@ -169,8 +181,8 @@ jobs:
echo "Displaying Local Manifests"
if [[ -z "${{ secrets.DISPLAY_FALSE }}" ]]; then
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} local_manifests
cat local_manifests/*.xml
$LOCAL_MANIFEST
cat .repo/local_manifests/*.xml
else
echo "Displaying is disabled through secrets."
fi
Expand All @@ -179,7 +191,7 @@ jobs:
PROJECTID: ${{ steps.proj-variables.outputs.PROJECTID }}
REPO_INIT: ${{ steps.proj-variables.outputs.REPO_INIT }}
LUNCH: ${{ steps.proj-variables.outputs.LUNCH }}

LOCAL_MANIFEST: ${{ steps.proj-variables.outputs.LOCAL_MANIFEST }}

test:
name: Test Local Manifests
Expand All @@ -193,11 +205,13 @@ jobs:
PROJECTID="${{ needs.prepare.outputs.PROJECTID }}"
REPO_INIT="${{ needs.prepare.outputs.REPO_INIT }}"
LUNCH="${{ needs.prepare.outputs.LUNCH }}"
LOCAL_MANIFEST="${{ needs.prepare.outputs.LOCAL_MANIFEST }}"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Download and configure 'repo'.
- name: Configure the 'repo' environment
Expand Down Expand Up @@ -237,13 +251,9 @@ jobs:
else
${{ github.event.inputs.BUILD_DIFFERENT_ROM }}
fi
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! $? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST
timeout 1m repo sync --force-sync || { exit_code=$?; [ $exit_code -eq 124 ] || (echo "Error: Process failed with exit code $exit_code"; exit $exit_code); }
du -csh . # Output Size when done
rm -rf .repo
Expand All @@ -253,6 +263,7 @@ jobs:
PROJECTID: ${{ needs.prepare.outputs.PROJECTID }}
REPO_INIT: ${{ needs.prepare.outputs.REPO_INIT }}
LUNCH: ${{ needs.prepare.outputs.LUNCH }}
LOCAL_MANIFEST: "${{ needs.prepare.outputs.LOCAL_MANIFEST }}"


build:
Expand All @@ -270,11 +281,13 @@ jobs:
PROJECTID="${{ needs.test.outputs.PROJECTID }}"
REPO_INIT="${{ needs.test.outputs.REPO_INIT }}"
LUNCH="${{ needs.test.outputs.LUNCH }}"
LOCAL_MANIFEST="${{ needs.test.outputs.LOCAL_MANIFEST }}"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Create a project folder
- name: Create Project Folders
Expand Down Expand Up @@ -419,12 +432,7 @@ jobs:
crave ${{ secrets.CRAVE_FLAGS }} run --no-patch --${CLEAN} "rm -rf .repo/local_manifests/ ${{ github.event.inputs.REMOVALS }} && \
# Clone local_manifests repository
$BUILD_DIFFERENT_ROM ; \
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! \$? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST; \
# Sync the repositories
/opt/crave/resync.sh && \
Expand Down
35 changes: 21 additions & 14 deletions .github/workflows/selfhosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,22 @@ jobs:
LUNCH="breakfast ${{ github.event.inputs.PRODUCT_NAME }} ${{ github.event.inputs.BUILD_TYPE }}"
fi
if [[ "${{ github.event.inputs.LOCAL_MANIFEST }}" =~ \.xml(/)?$ ]]; then
local_manifest_url="${{ github.event.inputs.LOCAL_MANIFEST }}"
export local_manifest_url="${local_manifest_url%/}" # remove trailing slash if it exists
export LOCAL_MANIFEST=$(mkdir -p .repo/local_manifests && rm -rf .repo/local_manifests/* || true && curl -o .repo/local_manifests/local_manifest.xml "${local_manifest_url}")
else
export LOCAL_MANIFEST="git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${github.event.inputs.LOCAL_MANIFEST_BRANCH} local_manifests"
fi
echo "Building on ${{ github.event.inputs.BASE_PROJECT }} project"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_OUTPUT"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_OUTPUT"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_OUTPUT"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_OUTPUT"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_OUTPUT"
- name: Display Run Parameters # Credit to azwhikaru for this part
run: |
Expand All @@ -208,8 +218,8 @@ jobs:
echo "Displaying Local Manifests"
if [[ -z "${{ secrets.DISPLAY_FALSE }}" ]]; then
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} local_manifests
cat local_manifests/*.xml
$LOCAL_MANIFEST
cat .repo/local_manifests/*.xml
else
echo "Displaying is disabled through secrets."
fi
Expand All @@ -218,6 +228,7 @@ jobs:
PROJECTID: ${{ steps.proj-variables.outputs.PROJECTID }}
REPO_INIT: ${{ steps.proj-variables.outputs.REPO_INIT }}
LUNCH: ${{ steps.proj-variables.outputs.LUNCH }}
LOCAL_MANIFEST: ${{ steps.proj-variables.outputs.LOCAL_MANIFEST }}

test:
name: Test Local Manifests
Expand All @@ -231,11 +242,13 @@ jobs:
PROJECTID="${{ needs.prepare.outputs.PROJECTID }}"
REPO_INIT="${{ needs.prepare.outputs.REPO_INIT }}"
LUNCH="${{ needs.prepare.outputs.LUNCH }}"
LOCAL_MANIFEST="${{ needs.prepare.outputs.LOCAL_MANIFEST }}"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Download and configure 'repo'.
- name: Configure the 'repo' environment
Expand Down Expand Up @@ -275,13 +288,9 @@ jobs:
else
${{ github.event.inputs.BUILD_DIFFERENT_ROM }}
fi
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! $? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST
timeout 1m repo sync --force-sync || { exit_code=$?; [ $exit_code -eq 124 ] || (echo "Error: Process failed with exit code $exit_code"; exit $exit_code); }
du -csh . # Output Size when done
rm -rf .repo
Expand All @@ -291,6 +300,7 @@ jobs:
PROJECTID: ${{ needs.prepare.outputs.PROJECTID }}
REPO_INIT: ${{ needs.prepare.outputs.REPO_INIT }}
LUNCH: ${{ needs.prepare.outputs.LUNCH }}
LOCAL_MANIFEST: "${{ needs.prepare.outputs.LOCAL_MANIFEST }}"

build:
timeout-minutes: 960
Expand All @@ -307,11 +317,13 @@ jobs:
PROJECTID="${{ needs.test.outputs.PROJECTID }}"
REPO_INIT="${{ needs.test.outputs.REPO_INIT }}"
LUNCH="${{ needs.test.outputs.LUNCH }}"
LOCAL_MANIFEST="${{ needs.test.outputs.LOCAL_MANIFEST }}"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LUNCH=$LUNCH" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Send Build 'start' notification
- name: Telegram Notification
Expand Down Expand Up @@ -444,12 +456,7 @@ jobs:
crave run --no-patch --${CLEAN} "rm -rf .repo/local_manifests/ ${{ github.event.inputs.REMOVALS }} && \
# Clone local_manifests repository
$BUILD_DIFFERENT_ROM ; \
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! \$? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST; \
# Sync the repositories
/opt/crave/resync.sh && \
Expand Down
45 changes: 26 additions & 19 deletions .github/workflows/twrp-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ jobs:
echo "Clean Build: ${{ github.event.inputs.CLEAN_BUILD }}"
echo "::endgroup::"
echo "Displaying Local Manifests"
if [[ -z "${{ secrets.DISPLAY_FALSE }}" ]]; then
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} local_manifests
cat local_manifests/*.xml
else
echo "Displaying is disabled through secrets."
fi
- name: Set Project variables
id: proj-variables
run: |
Expand All @@ -105,14 +97,34 @@ jobs:
export REPO_INIT="repo init -u https://github.com/minimal-manifest-twrp/platform_manifest_twrp_aosp.git -b twrp-12.1 --depth=1"
;;
esac
if [[ "${{ github.event.inputs.LOCAL_MANIFEST }}" =~ \.xml(/)?$ ]]; then
local_manifest_url="${{ github.event.inputs.LOCAL_MANIFEST }}"
export local_manifest_url="${local_manifest_url%/}" # remove trailing slash if it exists
export LOCAL_MANIFEST=$(mkdir -p .repo/local_manifests && rm -rf .repo/local_manifests/* || true && curl -o .repo/local_manifests/local_manifest.xml "${local_manifest_url}")
else
export LOCAL_MANIFEST="git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${github.event.inputs.LOCAL_MANIFEST_BRANCH} local_manifests"
fi
echo "Building on ${{ github.event.inputs.BASE_PROJECT }} project"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_OUTPUT"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_OUTPUT"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_OUTPUT"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_OUTPUT"
echo "Displaying Local Manifests"
if [[ -z "${{ secrets.DISPLAY_FALSE }}" ]]; then
$LOCAL_MANIFEST
cat .repo/local_manifests/*.xml
else
echo "Displaying is disabled through secrets."
fi
outputs:
PROJECTFOLDER: ${{ steps.proj-variables.outputs.PROJECTFOLDER }}
PROJECTID: ${{ steps.proj-variables.outputs.PROJECTID }}
REPO_INIT: ${{ steps.proj-variables.outputs.REPO_INIT }}
LOCAL_MANIFEST: ${{ steps.proj-variables.outputs.LOCAL_MANIFEST }}

test:
name: Test Local Manifests
Expand All @@ -129,6 +141,7 @@ jobs:
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Download and configure 'repo'.
- name: Configure the 'repo' environment
Expand Down Expand Up @@ -168,12 +181,8 @@ jobs:
else
${{ github.event.inputs.BUILD_DIFFERENT_ROM }}
fi
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! $? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST
timeout 1m repo sync --force-sync || { exit_code=$?; [ $exit_code -eq 124 ] || (echo "Error: Process failed with exit code $exit_code"; exit $exit_code); }
du -csh . # Output Size when done
Expand All @@ -183,6 +192,7 @@ jobs:
PROJECTFOLDER: ${{ needs.prepare.outputs.PROJECTFOLDER }}
PROJECTID: ${{ needs.prepare.outputs.PROJECTID }}
REPO_INIT: ${{ needs.prepare.outputs.REPO_INIT }}
LOCAL_MANIFEST: "${{ needs.prepare.outputs.LOCAL_MANIFEST }}"

build:
name: Build using foss.crave.io
Expand All @@ -198,10 +208,12 @@ jobs:
PROJECTFOLDER="${{ needs.test.outputs.PROJECTFOLDER }}"
PROJECTID="${{ needs.test.outputs.PROJECTID }}"
REPO_INIT="${{ needs.test.outputs.REPO_INIT }}"
LOCAL_MANIFEST="${{ needs.test.outputs.LOCAL_MANIFEST }}"
echo "PROJECTFOLDER=$PROJECTFOLDER" >> "$GITHUB_ENV"
echo "PROJECTID=$PROJECTID" >> "$GITHUB_ENV"
echo "REPO_INIT=$REPO_INIT" >> "$GITHUB_ENV"
echo "LOCAL_MANIFEST=$LOCAL_MANIFEST" >> "$GITHUB_ENV"
# Create a project folder
- name: Create Project Folders
Expand Down Expand Up @@ -345,12 +357,7 @@ jobs:
crave ${{ secrets.CRAVE_FLAGS }} run --no-patch --${CLEAN} "rm -rf .repo/local_manifests/ ${{ github.event.inputs.REMOVALS }} && \
# Clone local_manifests repository
$BUILD_DIFFERENT_ROM ; \
git clone ${{ github.event.inputs.LOCAL_MANIFEST }} --depth 1 -b ${{ github.event.inputs.LOCAL_MANIFEST_BRANCH }} .repo/local_manifests && \
if [ ! \$? == 0 ]; then \
curl -o .repo/local_manifests ${{ github.event.inputs.LOCAL_MANIFEST }}; \
echo "Git clone failed, downloading through curl instead..."; \
fi \
$LOCAL_MANIFEST; \
# Sync the repositories
/opt/crave/resync.sh && \
Expand Down
Loading

0 comments on commit a148797

Please sign in to comment.