|
| 1 | +# Workflow to check if the version in library.properties matches the latest release |
| 2 | +# If it does not, deletes the release and the corresponding tag |
| 3 | +name: Get Latest Release |
| 4 | + |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: |
| 8 | + - published |
| 9 | + |
| 10 | +jobs: |
| 11 | + get_release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + # Step 1: Checkout the repository code |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v2 |
| 18 | + |
| 19 | + # Step 2: Retrieve the latest release from the GitHub API |
| 20 | + - name: Get latest release |
| 21 | + id: get_latest_release |
| 22 | + run: | |
| 23 | + set -e |
| 24 | + response=$(curl --silent "https://api.github.com/repos/${{ github.repository }}/releases/latest") |
| 25 | + echo "Response: $response" |
| 26 | + latest_release=$(echo "$response" | jq -r .tag_name) |
| 27 | + echo "Latest release: $latest_release" |
| 28 | + echo "::set-output name=release::$latest_release" |
| 29 | + env: |
| 30 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + # Step 3: Check the version in the library.properties file and compare it with the latest release |
| 33 | + - name: Check version in library.properties |
| 34 | + id: compare_version |
| 35 | + run: | |
| 36 | + version=$(cat library.properties | grep "version" | cut -d'=' -f2) |
| 37 | + echo "Version in library.properties: $version" |
| 38 | + echo "Version in release: ${{ steps.get_latest_release.outputs.release }}" |
| 39 | + if [ "$version" == "${{ steps.get_latest_release.outputs.release }}" ]; then |
| 40 | + echo "Versions match!" |
| 41 | + else |
| 42 | + echo "Versions don't match." |
| 43 | + fi |
| 44 | + echo "::set-output name=version::$version" |
| 45 | +
|
| 46 | + # Step 4: Delete the release if the versions don't match |
| 47 | + - name: Delete release if failed |
| 48 | + if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }} |
| 49 | + uses: dev-drprasad/[email protected] |
| 50 | + with: |
| 51 | + tag_name: ${{ steps.get_latest_release.outputs.release }} |
| 52 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + # Step 5: Fail the workflow if the versions don't match |
| 57 | + - name: Fail workflow if failed |
| 58 | + if: ${{ steps.compare_version.outputs.version != steps.get_latest_release.outputs.release }} |
| 59 | + run: | |
| 60 | + echo "Versions don't match. Failing the workflow." |
| 61 | + exit 1 |
0 commit comments