From 79aed32c62e5e6c7df9d121ac2f3a1f02059158a Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 3 Jan 2024 18:19:36 +0800 Subject: [PATCH 1/4] ci: patch Cargo lockfile for release instead of build without `--locked` --- .github/workflows/release.yml | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad2dc4ef..3411e91d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,7 +91,6 @@ jobs: echo '```' } >> "$GITHUB_STEP_SUMMARY" - build: name: Build needs: meta @@ -119,25 +118,36 @@ jobs: with: os: ${{ matrix.os }} arch: ${{ matrix.arch }} - - name: Patch Cargo.toml (BSD sed) + - name: Patch Version (BSD sed) if: ${{ startsWith(matrix.os, 'macos') }} - working-directory: maa-cli run: | - sed -i "" '1,6 s/^version = .*/version = "${{ needs.meta.outputs.version }}"/' Cargo.toml - git diff Cargo.toml - - name: Patch Cargo.toml (GNU sed) + sed -i "" '1,6 s/(version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' maa-cli/Cargo.toml + sed -i "" 's/(name\s*=\s*"maa-cli"\s*\n\s*version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' Cargo.lock + { + echo "Patch Version (BSD sed, ${{ matrix.os }}, ${{ matrix.arch }})" + echo '```diff' + git diff + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + - name: Patch Version (GNU sed) if: ${{ !startsWith(matrix.os, 'macos') }} - working-directory: maa-cli run: | - sed -i '1,6 s/^version = .*/version = "${{ needs.meta.outputs.version }}"/' Cargo.toml - git diff Cargo.toml + sed -i '1,6 s/(version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' maa-cli/Cargo.toml + sed -i 's/(name\s*=\s*"maa-cli"\s*\n\s*version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' Cargo.lock + { + echo "Patch Version (GNU sed, ${{ matrix.os }}, ${{ matrix.arch }})" + echo '```diff' + git diff + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + git diff - name: Build env: CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1 CARGO_PROFILE_RELEASE_LTO: true CARGO_PROFILE_RELEASE_STRIP: true run: | - cargo build --release --package maa-cli \ + cargo build --release --package maa-cli --locked \ ${{ matrix.arch != 'x86_64' && '--features git2/vendored-openssl,reqwest/native-tls-vendored' || '' }} - name: Tar Artifact run: | From fe8918dfd946aa2dfe2c22b060ec1f2ebbe41bc6 Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 3 Jan 2024 18:47:31 +0800 Subject: [PATCH 2/4] fix --- .github/workflows/release.yml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3411e91d..f32396a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,29 +118,23 @@ jobs: with: os: ${{ matrix.os }} arch: ${{ matrix.arch }} - - name: Patch Version (BSD sed) - if: ${{ startsWith(matrix.os, 'macos') }} + - name: Patch Version run: | - sed -i "" '1,6 s/(version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' maa-cli/Cargo.toml - sed -i "" 's/(name\s*=\s*"maa-cli"\s*\n\s*version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' Cargo.lock - { - echo "Patch Version (BSD sed, ${{ matrix.os }}, ${{ matrix.arch }})" - echo '```diff' - git diff - echo '```' - } >> "$GITHUB_STEP_SUMMARY" - - name: Patch Version (GNU sed) - if: ${{ !startsWith(matrix.os, 'macos') }} - run: | - sed -i '1,6 s/(version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' maa-cli/Cargo.toml - sed -i 's/(name\s*=\s*"maa-cli"\s*\n\s*version\s*=\s*)"[^"]+"/\1"${{ needs.meta.outputs.version }}"/' Cargo.lock + MAA_VERSION="${{ needs.meta.outputs.version }}" + if [ $(uname) == "Darwin" ]; then + SED_INPUT_ARGS='-i ""' # BSD sed needs an extension for backup + else + SED_INPUT_ARGS="-i" + fi + S="[[:space:]]" # BSD sed doesn't support \s + sed $SED_INPUT_ARGS -E "s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" maa-cli/Cargo.toml + sed $SED_INPUT_ARGS -E "s/(name${S}*=${S}*\"maa-cli\"${S}*\\n${S}*version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" Cargo.lock { - echo "Patch Version (GNU sed, ${{ matrix.os }}, ${{ matrix.arch }})" + echo "Patch Version (${{ matrix.os }}, ${{ matrix.arch }})" echo '```diff' git diff echo '```' } >> "$GITHUB_STEP_SUMMARY" - git diff - name: Build env: CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1 From 89f63eb8ba583138ed465d74a20c6468e54728da Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 3 Jan 2024 18:50:29 +0800 Subject: [PATCH 3/4] fix --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f32396a6..1c5ace33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -127,7 +127,7 @@ jobs: SED_INPUT_ARGS="-i" fi S="[[:space:]]" # BSD sed doesn't support \s - sed $SED_INPUT_ARGS -E "s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" maa-cli/Cargo.toml + sed $SED_INPUT_ARGS -E "1,6 s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" maa-cli/Cargo.toml sed $SED_INPUT_ARGS -E "s/(name${S}*=${S}*\"maa-cli\"${S}*\\n${S}*version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" Cargo.lock { echo "Patch Version (${{ matrix.os }}, ${{ matrix.arch }})" From 2d4b3f0363d2bbd7eea7a2f9b9528ef365e9d010 Mon Sep 17 00:00:00 2001 From: Loong Date: Wed, 3 Jan 2024 19:25:31 +0800 Subject: [PATCH 4/4] fix --- .github/workflows/release.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c5ace33..ddf260d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -122,13 +122,16 @@ jobs: run: | MAA_VERSION="${{ needs.meta.outputs.version }}" if [ $(uname) == "Darwin" ]; then - SED_INPUT_ARGS='-i ""' # BSD sed needs an extension for backup + SED="sed -i '' -E" # BSD sed should use '' as backup extension else - SED_INPUT_ARGS="-i" + SED="sed -i -E" fi S="[[:space:]]" # BSD sed doesn't support \s - sed $SED_INPUT_ARGS -E "1,6 s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" maa-cli/Cargo.toml - sed $SED_INPUT_ARGS -E "s/(name${S}*=${S}*\"maa-cli\"${S}*\\n${S}*version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" Cargo.lock + $SED "1,6 s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" maa-cli/Cargo.toml + NL=$(grep -n -E "name${S}*=${S}*\"maa-cli\"" Cargo.lock | cut -d: -f1) + NS=$((NL - 1)) + NE=$((NL + 3)) + $SED "$NS,$NE s/(version${S}*=${S}*)\"[^\"]+\"/\1\"$MAA_VERSION\"/" Cargo.lock { echo "Patch Version (${{ matrix.os }}, ${{ matrix.arch }})" echo '```diff'