|
| 1 | +# |
| 2 | +# deploy.yml |
| 3 | +# |
| 4 | +# Rebuild the bugfix-2.1.x branch whenever 'import-2.1.x' is pushed |
| 5 | +# |
| 6 | + |
| 7 | +name: Deploy |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - import-2.1.x |
| 13 | + |
| 14 | +jobs: |
| 15 | + deploy: |
| 16 | + if: github.repository == 'MarlinFirmware/Configurations' |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Check out |
| 20 | + uses: actions/checkout@v3 |
| 21 | + |
| 22 | + # For each directory containing a changed config file, copy the .h files and build the code: |
| 23 | + - name: Deploy bugfix-2.1.x |
| 24 | + run: | |
| 25 | + IMPORT=import-2.1.x |
| 26 | + EXPORT=bugfix-2.1.x |
| 27 | + CEXA=config/examples |
| 28 | + CDEF=config/default |
| 29 | + BC=Configuration.h |
| 30 | + AC=Configuration_adv.h |
| 31 | +
|
| 32 | + git config user.email "[email protected]" |
| 33 | + git config user.name "Scott Lahteine" |
| 34 | +
|
| 35 | + echo "- Initializing BASE branch..." |
| 36 | +
|
| 37 | + # Copy to a temporary location |
| 38 | + TEMP=$( mktemp -d ) ; cp -R config $TEMP |
| 39 | +
|
| 40 | + # Strip all #error lines |
| 41 | + IFS=$'\n'; set -f |
| 42 | + for fn in $( find $TEMP/config -type f -name "Configuration.h" ); do |
| 43 | + sed -i~ -e "20,30{/#error/d}" "$fn" |
| 44 | + rm "$fn~" |
| 45 | + done |
| 46 | + unset IFS; set +f |
| 47 | +
|
| 48 | + # Create 'BASE' as a copy of 'init-repo' (README, LICENSE, etc.) |
| 49 | + git fetch origin init-repo >/dev/null |
| 50 | + git checkout origin/init-repo -b BASE >/dev/null || exit |
| 51 | +
|
| 52 | + # Copy all config files into place |
| 53 | + echo "- Copying configs from fresh $IMPORT..." |
| 54 | + cp -R "$TEMP/config" . >/dev/null |
| 55 | +
|
| 56 | + echo "- Deleting extras" |
| 57 | +
|
| 58 | + # Delete anything that's not a Configuration file |
| 59 | + find config -type f \! -name "Conf*.h" -exec rm "{}" \; |
| 60 | +
|
| 61 | + # Init Cartesian/SCARA/TPARA configurations to default |
| 62 | + echo "- Initializing configs to default state..." |
| 63 | +
|
| 64 | + find "$CEXA" -name $BC -print0 \ |
| 65 | + | while read -d $'\0' F ; do cp "$CDEF/$BC" "$F" >/dev/null ; done |
| 66 | + find "$CEXA" -name $AC -print0 \ |
| 67 | + | while read -d $'\0' F ; do cp "$CDEF/$AC" "$F" >/dev/null ; done |
| 68 | +
|
| 69 | + # Update the %VERSION% in the README.md file |
| 70 | + VERS=$( echo $EXPORT | sed 's/release-//' ) |
| 71 | + eval "sed -E -i~ -e 's/%VERSION%/$VERS/g' README.md" |
| 72 | + rm -f README.md~ |
| 73 | +
|
| 74 | + # Commit the 'BASE', ready for customizations |
| 75 | + git add . >/dev/null && git commit --amend --no-edit ;#>/dev/null |
| 76 | +
|
| 77 | + # Create a new branch from 'BASE' for the final result |
| 78 | + echo "- Creating 'built-temp' branch..." |
| 79 | + git checkout -b built-temp >/dev/null || exit |
| 80 | +
|
| 81 | + # Delete temporary branch |
| 82 | + git branch -D BASE 2>/dev/null |
| 83 | +
|
| 84 | + echo "- Applying customizations..." |
| 85 | + cp -R "$TEMP/config" . |
| 86 | + find config -type f \! -name "Configuration*" -exec rm "{}" \; |
| 87 | +
|
| 88 | + addpathlabels() { |
| 89 | + find config -name "Conf*.h" -print0 | while read -d $'\0' fn ; do |
| 90 | + fldr=$(dirname "$fn") |
| 91 | + blank_line=$(awk '/^\s*$/ {print NR; exit}' "$fn") |
| 92 | + sed -i~ "${blank_line}i\\\n#define CONFIG_EXAMPLES_DIR \"$fldr\"\\ " "$fn" |
| 93 | + rm -f "$fn~" |
| 94 | + done |
| 95 | + } |
| 96 | +
|
| 97 | + echo "- Applying path labels..." |
| 98 | + addpathlabels >/dev/null 2>&1 |
| 99 | +
|
| 100 | + git add . >/dev/null && git commit -m "Examples Customizations" ;#>/dev/null |
| 101 | +
|
| 102 | + echo "- Adding all the extras..." |
| 103 | + cp -R "$TEMP/config" . |
| 104 | +
|
| 105 | + echo "- Applying path labels..." |
| 106 | + addpathlabels >/dev/null 2>&1 |
| 107 | +
|
| 108 | + git add . >/dev/null && git commit -m "Examples Extras" ;#>/dev/null |
| 109 | +
|
| 110 | + echo "- Replace $EXPORT branch" |
| 111 | + git fetch origin $EXPORT >/dev/null |
| 112 | + git checkout >/dev/null $EXPORT |
| 113 | + git reset --hard built-temp |
| 114 | + git push -f |
| 115 | + git branch -D built-temp |
| 116 | +
|
| 117 | + rm -rf $TEMP |
0 commit comments