From 63c07ba0b1da1d9abc68865344380f172b2ac478 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:31:35 +0100 Subject: [PATCH 1/3] Add check-release-version workflow --- .github/workflows/check-release-version.yml | 61 +++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 .github/workflows/check-release-version.yml diff --git a/.github/workflows/check-release-version.yml b/.github/workflows/check-release-version.yml new file mode 100644 index 0000000..12e033c --- /dev/null +++ b/.github/workflows/check-release-version.yml @@ -0,0 +1,61 @@ +# Workflow to check if the version in library.properties matches the latest release +# If it does not, deletes the release and the corresponding tag +name: Get Latest Release + +on: + release: + types: + - published + +jobs: + get_release: + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the repository code + - name: Checkout code + uses: actions/checkout@v2 + + # Step 2: Retrieve the latest release from the GitHub API + - name: Get latest release + id: get_latest_release + run: | + set -e + response=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest") + echo "Response: $response" + latest_release=$(echo "$response" | jq -r .tag_name) + echo "Latest release: $latest_release" + echo "::set-output name=release::$latest_release" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Step 3: Check the version in the library.properties file and compare it with the latest release + - name: Check version in library.properties + id: compare_version + run: | + version=$(cat library.properties | grep "version" | cut -d'=' -f2) + echo "Version in library.properties: $version" + echo "Version in release: ${{ steps.get_latest_release.outputs.release }}" + if [ "$version" == "${{ steps.get_latest_release.outputs.release }}" ]; then + echo "Versions match!" + else + echo "Versions don't match." + fi + echo "::set-output name=version::$version" + + # Step 4: Delete the release if the versions don't match + - name: Delete release if failed + if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }} + uses: dev-drprasad/delete-tag-and-release@v0.2.1 + with: + tag_name: ${{ steps.get_latest_release.outputs.release }} + github_token: ${{ secrets.GITHUB_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # Step 5: Fail the workflow if the versions don't match + - name: Fail workflow if failed + if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }} + run: | + echo "Versions don't match. Failing the workflow." + exit 1 From 64d2ef014fa02f9acef8ab8974813a85802872fe Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:32:33 +0100 Subject: [PATCH 2/3] correct library.properties version --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d81d519..82711d1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_UnifiedStorage -version=1.0.0 +version=1.1.0 author=Arduino maintainer=Arduino sentence=Simplify cross-device storage management on Portenta platforms with a single library supporting SD, Flash, and USB storage access. From 748693f48005df202eab6eb351aa10c3ab3804d2 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:02:57 +0100 Subject: [PATCH 3/3] ci: add error directly to echo message Co-authored-by: per1234 --- .github/workflows/check-release-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-release-version.yml b/.github/workflows/check-release-version.yml index 12e033c..362861a 100644 --- a/.github/workflows/check-release-version.yml +++ b/.github/workflows/check-release-version.yml @@ -57,5 +57,5 @@ jobs: - name: Fail workflow if failed if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }} run: | - echo "Versions don't match. Failing the workflow." + echo "::error::Versions don't match. Failing the workflow." exit 1