Skip to content

Commit

Permalink
DAT-16035 Fix draft release artifacts removal (#91)
Browse files Browse the repository at this point in the history
* chore(get_draft_release.sh): remove unused script

feat(extension-attach-artifact-release.yml): improve artifact management in release workflow

The get_draft_release.sh script was removed as it was no longer being used in the project.

In the extension-attach-artifact-release.yml workflow:
- The step to get the release tag was replaced with a step to get the latest draft release ID using the GitHub API. This change allows for more flexibility in managing the release.
- The step to delete outdated files from the draft release was replaced with a step to list the artifacts in the release using the GitHub API. This change provides better visibility into the artifacts that will be deleted.
- A new step was added to delete the artifacts from the release. This step iterates over the list of artifact IDs and deletes each artifact using the GitHub API. This change improves the management of artifacts in the release process.

* fix(extension-attach-artifact-release.yml): update API endpoint to retrieve latest draft release ID to handle cases where there are no draft releases
fix(extension-attach-artifact-release.yml): update API endpoint to list artifacts in release to handle cases where there are no artifacts
fix(extension-attach-artifact-release.yml): update conditional check to delete artifacts only if ARTIFACTS_TO_DELETE is not null

* fix(extension-attach-artifact-release.yml): fix syntax error in echo command by adding missing closing double quotes
fix(extension-attach-artifact-release.yml): fix syntax error in echo command by adding missing closing double quotes

* chore(extension-attach-artifact-release.yml): clean up and improve artifact deletion process

The changes in this commit include:
- Cleaning up the list of artifacts to delete by removing extra spaces and trailing comma
- Storing the cleaned list of artifacts to delete in the `ARTIFACTS_TO_DELETE` environment variable
- Modifying the artifact deletion loop to iterate over the cleaned list of artifacts
- Updating the log message to display the ID of the deleted artifact

These changes were made to improve the readability and maintainability of the artifact deletion process in the GitHub Actions workflow.

* chore(create-release.yml): update sonar-push.yml version to v0.4.8 for better compatibility
chore(extension-attach-artifact-release.yml): update script file versions to v0.4.8 for better compatibility
chore(extension-release-prepare.yml): update extension-release-rollback.yml version to v0.4.8 for better compatibility
chore(extension-release-published.yml): update extension-release-prepare.yml version to v0.4.8 for better compatibility
chore(os-extension-test.yml): update sonar-pull-request.yml version to v0.4.8 for better compatibility
chore(package-deb.yml): update file versions to v0.4.8 for better compatibility
chore(pom-release-published.yml): update extension-release-prepare.yml version to v0.4.8 for better compatibility
chore(pro-extension-test.yml): update sonar-pull-request.yml version to v0.4.8 for better compatibility
  • Loading branch information
jandroav authored Oct 6, 2023
1 parent fbd65ae commit 2e9e13c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 65 deletions.
37 changes: 0 additions & 37 deletions .github/get_draft_release.sh

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
sonar:
uses: liquibase/build-logic/.github/workflows/sonar-push.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/sonar-push.yml@v0.4.8
secrets: inherit

create-release:
Expand Down
48 changes: 30 additions & 18 deletions .github/workflows/extension-attach-artifact-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:

- name: Get Reusable Script Files
run: |
curl -o $PWD/.github/get_draft_release.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/.github/get_draft_release.sh
curl -o $PWD/.github/sign_artifact.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/.github/sign_artifact.sh
curl -o $PWD/.github/upload_asset.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/.github/upload_asset.sh
curl -o $PWD/.github/get_draft_release.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/.github/get_draft_release.sh
curl -o $PWD/.github/sign_artifact.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/.github/sign_artifact.sh
curl -o $PWD/.github/upload_asset.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/.github/upload_asset.sh
chmod +x $PWD/.github/get_draft_release.sh
chmod +x $PWD/.github/sign_artifact.sh
chmod +x $PWD/.github/upload_asset.sh
Expand All @@ -60,21 +60,33 @@ jobs:
id: get-artifact-id
run: echo "artifact_id=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> $GITHUB_ENV

- name: Get Release Tag
id: get-release-tag
run: echo "release_tag=$(./.github/get_draft_release.sh TAG)" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Get latest draft release ID
id: get-release
run: |
LATEST_DRAFT_RELEASE=$(curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases?per_page=1" | jq -r 'if .[].draft == true then .[].id else empty end')
echo "Latest Draft Release ID: $LATEST_DRAFT_RELEASE"
echo "RELEASE_ID=$LATEST_DRAFT_RELEASE" >> $GITHUB_ENV
- name: Delete Outdated Files from Draft Release
id: delete-outdated-release-asset
uses: mknejp/delete-release-assets@v1
with:
token: ${{ secrets.BOT_TOKEN }}
tag: ${{ env.release_tag }}
fail-if-no-assets: false
fail-if-no-release: false
assets: '*.*'
- name: List artifacts in release
if: env.RELEASE_ID != '' && env.RELEASE_ID != null
id: list-artifacts
run: |
RELEASE_ID="${{ env.RELEASE_ID }}"
ARTIFACTS=$(curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets" | jq -r '.[].id')
echo "Artifacts to delete: $ARTIFACTS"
ARTIFACTS_CLEANED=$(echo "$ARTIFACTS" | tr -s '[:space:]' ',' | sed 's/,$//')
echo "ARTIFACTS_TO_DELETE=$ARTIFACTS_CLEANED" >> $GITHUB_ENV
- name: Delete artifacts
if: env.ARTIFACTS_TO_DELETE != null
run: |
RELEASE_ID="${{ env.RELEASE_ID }}"
ARTIFACTS_TO_DELETE="${{ env.ARTIFACTS_TO_DELETE }}"
IFS=',' read -ra values <<< "$ARTIFACTS_TO_DELETE"
for value in "${values[@]}"; do
curl -X DELETE -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/assets/$value"
echo "Deleted artifact ID: $value"
done
- name: Import GPG key
id: import_gpg
Expand Down Expand Up @@ -103,7 +115,7 @@ jobs:
- name: Get upload_zip.sh Script File
if: inputs.zip == 'true'
run: |
curl -o $PWD/.github/upload_zip.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/.github/upload_zip.sh
curl -o $PWD/.github/upload_zip.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/.github/upload_zip.sh
chmod +x $PWD/.github/upload_zip.sh
- name: Attach Zip File to Draft Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/extension-release-prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ jobs:
release-rollback:
needs: prepare-release
if: ${{ always() && contains(needs.*.result, 'failure') }}
uses: liquibase/build-logic/.github/workflows/extension-release-rollback.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/extension-release-rollback.yml@v0.4.8
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/extension-release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ jobs:
maven-release:
needs: release
uses: liquibase/build-logic/.github/workflows/extension-release-prepare.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/extension-release-prepare.yml@v0.4.8
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/os-extension-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ jobs:
sonar-pr:
needs: [ unit-test ]
uses: liquibase/build-logic/.github/workflows/sonar-pull-request.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/sonar-pull-request.yml@v0.4.8
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/package-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ jobs:
# Under the src folder is where specific packages files live. The GitHub action inputs will modify the universal package-deb-pom.xml to tell the process which assets to use during the packaging step
mkdir -p $PWD/.github/src/${{ inputs.artifactId }}/deb/control
mkdir -p $PWD/.github/src/${{ inputs.artifactId }}/main/archive
curl -o $PWD/.github/src/${{ inputs.artifactId }}/deb/control/control https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/src/${{ inputs.artifactId }}/deb/control/control
curl -o $PWD/.github/src/${{ inputs.artifactId }}/deb/control/postinst https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/src/${{ inputs.artifactId }}/deb/control/postinst
curl -o $PWD/.github/src/${{ inputs.artifactId }}/main/archive/${{ inputs.artifactId }}-env.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/src/${{ inputs.artifactId }}/main/archive/${{ inputs.artifactId }}-env.sh
curl -o $PWD/.github/package-deb-pom.xml https://raw.githubusercontent.com/liquibase/build-logic/v0.4.7/.github/package-deb-pom.xml
curl -o $PWD/.github/src/${{ inputs.artifactId }}/deb/control/control https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/src/${{ inputs.artifactId }}/deb/control/control
curl -o $PWD/.github/src/${{ inputs.artifactId }}/deb/control/postinst https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/src/${{ inputs.artifactId }}/deb/control/postinst
curl -o $PWD/.github/src/${{ inputs.artifactId }}/main/archive/${{ inputs.artifactId }}-env.sh https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/src/${{ inputs.artifactId }}/main/archive/${{ inputs.artifactId }}-env.sh
curl -o $PWD/.github/package-deb-pom.xml https://raw.githubusercontent.com/liquibase/build-logic/v0.4.8/.github/package-deb-pom.xml
- name: Set up Maven
uses: stCarolas/setup-maven@v4.5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pom-release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ jobs:
maven-release:
needs: release
uses: liquibase/build-logic/.github/workflows/extension-release-prepare.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/extension-release-prepare.yml@v0.4.8
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/pro-extension-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,5 @@ jobs:
sonar-pr:
needs: [ unit-test ]
uses: liquibase/build-logic/.github/workflows/sonar-pull-request.yml@v0.4.7
uses: liquibase/build-logic/.github/workflows/sonar-pull-request.yml@v0.4.8
secrets: inherit

0 comments on commit 2e9e13c

Please sign in to comment.