githubofkrishnadhas creating secrets in devwithkrishna #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: create-organization-github-secrets-from-workflow | |
on: | |
workflow_dispatch: | |
inputs: | |
organization: | |
type: string | |
default: 'devwithkrishna' | |
description: 'The GitHub organization where the repository will be created.' | |
required: true | |
secret_name: | |
type: string | |
description: "Secret name to create/update on org level" | |
required: true | |
secret_value: | |
type: string | |
description: "Secret value to add" | |
required: true | |
run-name: ${{ github.actor }} creating secrets in ${{ inputs.organization }} | |
jobs: | |
create-organization-github-secrets-from-workflow: | |
runs-on: ubuntu-latest | |
steps: | |
- name: git checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.11' | |
- name: package installations | |
run: | | |
pip install pipenv | |
pipenv install | |
- name: get public key | |
id: get-public-key | |
env: | |
GH_TOKEN: ${{ secrets.DEVWITHKRISHNA_PERSONAL_ACCESS_TOKEN }} | |
run: | | |
public_key=$(bash get_public_key.sh ${{inputs.organization}}) | |
echo "PUBLIC_KEY=$public_key" >> $GITHUB_OUTPUT | |
- name: get public key id | |
id: get-public-key-id | |
env: | |
GH_TOKEN: ${{ secrets.DEVWITHKRISHNA_PERSONAL_ACCESS_TOKEN }} | |
run: | | |
public_key_id=$(bash get_public_key_id.sh ${{inputs.organization}}) | |
echo "PUBLIC_KEY_ID=$public_key_id" >> $GITHUB_OUTPUT | |
- name: Encrypt secret | |
id: encrypt-secret | |
env: | |
PUBLIC_KEY: ${{ steps.get-public-key.outputs.public_key }} | |
SECRET_VALUE: ${{ inputs.secret_value }} | |
run: | | |
pipenv run python3 encrypt_using_libnacl.py | |
- name: create or update org secret | |
env: | |
organization: ${{ inputs.organization }} | |
secret_name: ${{ inputs.secret_name }} | |
ENCRYPTED_SECRET: ${{ env.ENCRYPTED_SECRET }} | |
PUBLIC_KEY_ID: ${{ steps.get-public-key-id.outputs.public_key_id }} | |
GH_TOKEN: ${{ secrets.DEVWITHKRISHNA_PERSONAL_ACCESS_TOKEN }} | |
run: | | |
pipenv run python3 create_or_update_github_org_secret.py | |
- name: Completed | |
run: | | |
echo "program completed successfully" |