Skip to content

Instantly share code, notes, and snippets.

@philip-gai
Last active January 14, 2024 18:11
Show Gist options
  • Select an option

  • Save philip-gai/2b21293b178aa6ea6903e99cc1c32c4f to your computer and use it in GitHub Desktop.

Select an option

Save philip-gai/2b21293b178aa6ea6903e99cc1c32c4f to your computer and use it in GitHub Desktop.

Revisions

  1. philip-gai revised this gist Mar 30, 2022. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gh-set-secret.yml
    Original file line number Diff line number Diff line change
    @@ -4,20 +4,17 @@
    #
    # Notes:
    # - You can tell that it works because it masks the secret_body in the echo secret step after it creates the secret 😄
    # - If you don't want to have to call gh auth login, set the env var GH_TOKEN or GITHUB_TOKEN to ${{ secrets.PAT_TOKEN }} and skip that step
    # - If you don't want to have to pass --repo to gh secret set, then put the actions/checkout@v2 step before the gh secret set step
    #

    name: gh-set-secret

    on:
    workflow_dispatch:

    env:
    pat_token: ${{ secrets.PAT_TOKEN }}
    pat_token: ${{ secrets.PAT_TOKEN }} # Permissions: repo (all) and read:org
    secret_name: HELLO_WORLD
    secret_body: "Hello World!"
    secret_repo: "philip-gai/philip-gai"
    secret_environment: sandbox

    jobs:
    @@ -26,18 +23,21 @@ jobs:
    steps:
    - name: gh auth login
    shell: bash
    run: gh auth login --with-token <<< "${{ env.pat_token }}"
    run: gh auth login --with-token <<< $pat_token
    - name: gh secret set env
    shell: bash
    run: gh secret set "${{ env.secret_name }}" --env "${{ env.secret_environment }}" --body "${{ env.secret_body }}" --repo "${{ env.secret_repo }}"
    run: |
    repository='${{ github.repository }}'
    gh secret set "$secret_name" --env "$secret_environment" --body "$secret_body" --repo $repository
    gh-test-secret:
    needs: [gh-set-secret]
    runs-on: ubuntu-latest
    environment:
    name: ${{ env.secret_environment }}
    name: sandbox
    env:
    secret: ${{ secrets.HELLO_WORLD }}
    steps:
    - name: echo secret
    shell: bash
    run: echo "$HELLO_WORLD"
    run: |
    echo "Secret: $secret"
  2. philip-gai created this gist Nov 5, 2021.
    43 changes: 43 additions & 0 deletions gh-set-secret.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    # Prerequisites:
    # - Create a secret with your PAT token. Permissions needed: repo (all) and read:org
    # - Create the HELLO_WORLD secret in your environment with some dummy initial value
    #
    # Notes:
    # - You can tell that it works because it masks the secret_body in the echo secret step after it creates the secret 😄
    # - If you don't want to have to call gh auth login, set the env var GH_TOKEN or GITHUB_TOKEN to ${{ secrets.PAT_TOKEN }} and skip that step
    # - If you don't want to have to pass --repo to gh secret set, then put the actions/checkout@v2 step before the gh secret set step
    #

    name: gh-set-secret

    on:
    workflow_dispatch:

    env:
    pat_token: ${{ secrets.PAT_TOKEN }}
    secret_name: HELLO_WORLD
    secret_body: "Hello World!"
    secret_repo: "philip-gai/philip-gai"
    secret_environment: sandbox

    jobs:
    gh-set-secret:
    runs-on: ubuntu-latest
    steps:
    - name: gh auth login
    shell: bash
    run: gh auth login --with-token <<< "${{ env.pat_token }}"
    - name: gh secret set env
    shell: bash
    run: gh secret set "${{ env.secret_name }}" --env "${{ env.secret_environment }}" --body "${{ env.secret_body }}" --repo "${{ env.secret_repo }}"
    gh-test-secret:
    needs: [gh-set-secret]
    runs-on: ubuntu-latest
    environment:
    name: ${{ env.secret_environment }}
    env:
    secret: ${{ secrets.HELLO_WORLD }}
    steps:
    - name: echo secret
    shell: bash
    run: echo "$HELLO_WORLD"