Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cleaning action #641

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,29 @@ jobs:
tags: |
${{ env.GH_IMAGE }}
${{ env.DH_IMAGE }}

delete_untagged:
runs-on: ubuntu-latest
needs:
- release
- source
steps:
- name: Delete Untagged Images
uses: actions/github-script@v3
with:
github-token: ${{ secrets.DELETE_PACKAGES_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this use the normal GITHUB_TOKEN? That one has read/write permissions to packages and we are not planning to run this from a fork afaik.

Copy link
Contributor Author

@vatanaksoytezer vatanaksoytezer Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is we would need admin access to delete the images. The token does not need write access to packages, it has a seperate delete permission (which needs read access though). The relevant bit for permissions is documented here: https://docs.github.com/en/packages/learn-github-packages/deleting-and-restoring-a-package#required-permissions-to-delete-or-restore-a-package and https://docs.github.com/en/rest/reference/packages#delete-a-package-version-for-the-authenticated-user

Copy link
Contributor Author

@vatanaksoytezer vatanaksoytezer Aug 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are two failed tests with GITHUB_TOKEN:

https://github.com/vatanaksoytezer/moveit2/actions/runs/1170069287 https://github.com/vatanaksoytezer/moveit2/actions/runs/1170061546

I assume if you could specify delete permission through action that would be feasible but as of now GHA does not support delete packages permission to be defined under permissions.

script: |
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ env.PACKAGE_NAME }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
for(version of response.data) {
if (version.metadata.container.tags.length == 0) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ env.PACKAGE_NAME }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}
env:
OWNER: ros-planning
PACKAGE_NAME: moveit2
PER_PAGE: 1000