Skip to content

Commit

Permalink
Add reusable workflow to delete an org session
Browse files Browse the repository at this point in the history
* **Get GitHub Access Token**: Retrieve GitHub Access Token from the specified environment and store it in the GitHub environment variable.
* **Delete Org Session**: Delete the org session from the specified environment using the retrieved GitHub Access Token.
* **Add Job Summary**: Add a job summary to the GitHub step summary, including the environment name and status of the org session deletion.
  • Loading branch information
jlantz committed Oct 30, 2024
1 parent 28bb97e commit 2e88b66
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .github/workflows/delete-org-session.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Delete Org Session

on:
workflow_call:
inputs:
environment_name:
description: "The name of the GitHub Environment to delete the org session from"
required: true
type: string
github_auth_environment:
description: "The name of the GitHub Environment to get the GitHub Access token from"
required: true
type: string
secrets:
github-token:
required: true

jobs:
delete-org-session:
name: "Delete Org Session"
runs-on: ubuntu-latest
steps:
- name: Get GitHub Access Token
run: |
echo "Retrieving GitHub Access Token from environment: ${{ inputs.github_auth_environment }}"
GITHUB_ACCESS_TOKEN=$(gh api \
-H "Authorization: token ${{ secrets.github-token }}" \
"/repos/${{ github.repository }}/environments/${{ inputs.github_auth_environment }}/variables/GITHUB_ACCESS_TOKEN" \
| jq -r '.value')
echo "GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN}" >> $GITHUB_ENV
shell: bash

- name: Delete Org Session
run: |
echo "Deleting org session from environment: ${{ inputs.environment_name }}"
gh api \
-X DELETE \
-H "Authorization: token ${{ env.GITHUB_ACCESS_TOKEN }}" \
"/repos/${{ github.repository }}/environments/${{ inputs.environment_name }}/variables/ACCESS_TOKEN"
shell: bash

- name: Add Job Summary
run: |
echo "## Org Session Deletion Summary" >> $GITHUB_STEP_SUMMARY
echo "Environment: ${{ inputs.environment_name }}" >> $GITHUB_STEP_SUMMARY
echo "Status: Org session deleted successfully" >> $GITHUB_STEP_SUMMARY
shell: bash
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ requests = "^2.28.1"
click = "^8.1.3"
rich_click = "^1.0.0"
pynacl = "^1.4.0"
cryptography = "^43.0.3"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
Expand Down

0 comments on commit 2e88b66

Please sign in to comment.