Skip to content

Commit

Permalink
Re-enabling attempt to delete environment (#89)
Browse files Browse the repository at this point in the history
* Re-enabling attempt to delete environment, and log a message with explanations if cannot be done
  • Loading branch information
crohr authored Aug 24, 2024
1 parent 27cbbc5 commit 7eecd65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
description: "Label to use for triggering preview deployments"
default: "pullpreview"
github_token:
description: "The personal access token used to update the status of your commit"
description: "The GitHub access token used to perform GitHub API operations. A custom token is only required for auto-cleanup of GitHub environment objects."
default: "${{ github.token }}"
admins:
description: "Logins of GitHub users that will have their SSH key installed on the instance, comma-separated"
Expand Down
11 changes: 8 additions & 3 deletions lib/pull_preview/github_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,15 @@ def self.destroy_environment(repo, environment)
deploys.each do |deployment|
PullPreview.octokit.delete(deployment.url)
end
# This requires repository permission, which the GitHub Action token cannot get, so cannot delete the environment unfortunately
# PullPreview.octokit.delete_environment(repo, environment)
# This requires repository permission, which the default GitHub Action token cannot get, so this will fail if the github_token input is not used.
# Logging a warning message to let the user know that he will have to clean the environment manually.
begin
PullPreview.octokit.delete_environment(repo, environment)
rescue Octokit::Error => e
PullPreview.logger.warn "Unable to destroy the environment #{environment.inspect}: #{e.message}. To destroy the environment object on GitHub, you will have to manually delete it from the GitHub UI, or pass a GitHub token with repository permissions to the action. This does not affect the cleaning of instances, only the GitHub environment object."
end
rescue => e
PullPreview.logger.warn "Unable to destroy environment #{environment.inspect}: #{e.message}"
PullPreview.logger.error "Unable to destroy environment #{environment.inspect}: #{e.message}"
end

def initialize(github_context, app_path, opts = {})
Expand Down

0 comments on commit 7eecd65

Please sign in to comment.