Skip to content

Commit

Permalink
CI: extract branch name safely
Browse files Browse the repository at this point in the history
Prior to this commit, we got errors in CI like The artifact name is not valid: bitcoin-patched-refs\/pull\/4\/merge-28.99.0-x86_64-unknown-linux-gnu
  • Loading branch information
octobocto committed Oct 7, 2024
1 parent 8592f07 commit 34fb3b8
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ jobs:
- name: 'Set environment variables: version number'
run: |
BITCOIN_PATCHED_VERSION=$(grep -oP "(?<=^CMAKE_PROJECT_VERSION:STATIC=).+(?=)" build/CMakeCache.txt)
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Escape '/', '\' and space characters
ESCAPED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\\ ]/\\&/g')
if [ "$ESCAPED_BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${ESCAPED_BRANCH_NAME}-${BITCOIN_PATCHED_VERSION}"
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///' | sed 's/refs\/pull\/\([0-9]*\)\/merge/pr-\1/')
SAFE_BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
if [ "$BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${BITCOIN_PATCHED_VERSION}-${SAFE_BRANCH_NAME}"
fi
echo "BITCOIN_PATCHED_VERSION=$BITCOIN_PATCHED_VERSION" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
Expand All @@ -63,7 +64,6 @@ jobs:
build/src/bitcoin-cli
build/src/qt/bitcoin-qt
build-windows:
name: Build Windows binaries
runs-on: ubuntu-24.04
Expand Down Expand Up @@ -107,12 +107,13 @@ jobs:
- name: 'Set environment variables: version number'
run: |
BITCOIN_PATCHED_VERSION=$(grep -oP "(?<=^CMAKE_PROJECT_VERSION:STATIC=).+(?=)" build/CMakeCache.txt)
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Escape '/', '\' and space characters
ESCAPED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\\ ]/\\&/g')
if [ "$ESCAPED_BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${ESCAPED_BRANCH_NAME}-${BITCOIN_PATCHED_VERSION}"
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///' | sed 's/refs\/pull\/\([0-9]*\)\/merge/pr-\1/')
SAFE_BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
if [ "$BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${BITCOIN_PATCHED_VERSION}-${SAFE_BRANCH_NAME}"
fi
echo "BITCOIN_PATCHED_VERSION=$BITCOIN_PATCHED_VERSION" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -162,12 +163,13 @@ jobs:
- name: 'Set environment variables: version number'
run: |
BITCOIN_PATCHED_VERSION=$(ggrep -oP "(?<=^CMAKE_PROJECT_VERSION:STATIC=).+(?=)" build/CMakeCache.txt)
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Escape '/', '\' and space characters
ESCAPED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\\ ]/\\&/g')
if [ "$ESCAPED_BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${ESCAPED_BRANCH_NAME}-${BITCOIN_PATCHED_VERSION}"
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///' | sed 's/refs\/pull\/\([0-9]*\)\/merge/pr-\1/')
SAFE_BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
if [ "$BRANCH_NAME" != "master" ]; then
BITCOIN_PATCHED_VERSION="${BITCOIN_PATCHED_VERSION}-${SAFE_BRANCH_NAME}"
fi
echo "BITCOIN_PATCHED_VERSION=$BITCOIN_PATCHED_VERSION" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
Expand All @@ -187,18 +189,18 @@ jobs:
steps:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Zip artifacts
run: |
ARTIFACT_PREFIX=''
BRANCH_NAME=${GITHUB_REF#refs/heads/}
# Escape '/', '\' and space characters
ESCAPED_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed 's/[\/\\ ]/\\&/g')
if [ "$ESCAPED_BRANCH_NAME" != "master" ]; then
ARTIFACT_PREFIX="L1-bitcoin-patched-${ESCAPED_BRANCH_NAME}-latest"
BRANCH_NAME=$(echo $GITHUB_REF | sed 's/refs\/heads\///' | sed 's/refs\/pull\/\([0-9]*\)\/merge/pr-\1/')
SAFE_BRANCH_NAME=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9._-]/-/g')
if [ "$BRANCH_NAME" != "master" ]; then
ARTIFACT_PREFIX="L1-bitcoin-patched-${SAFE_BRANCH_NAME}"
else
ARTIFACT_PREFIX="L1-bitcoin-patched-latest"
fi
mv bitcoin-patched-*-x86_64-apple-darwin "${ARTIFACT_PREFIX}-x86_64-apple-darwin"
zip -r "${ARTIFACT_PREFIX}-x86_64-apple-darwin.zip" "${ARTIFACT_PREFIX}-x86_64-apple-darwin"
mv bitcoin-patched-*-x86_64-w64-mingw32 "${ARTIFACT_PREFIX}-x86_64-w64-mingw32"
Expand All @@ -214,4 +216,4 @@ jobs:
pass: ${{ secrets.RELEASES_SERVER_PW }}
port: 22
scp: |
'L1-bitcoin-patched-*latest-*.zip' => '/var/www/html/'
'L1-bitcoin-patched-*.zip' => '/var/www/html/'

0 comments on commit 34fb3b8

Please sign in to comment.