Last active
November 12, 2024 22:03
-
-
Save clarkritchie/def05211e6dd0ec6a8e1edd48f0f822b to your computer and use it in GitHub Desktop.
Print GitHub Secret
This file contains hidden or 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: Reveal a Secret | |
| # Set a secret from the command line: | |
| # | |
| # gh secret set TOP_SECRET -b"foobarbaz" -Rdexcom-inc/sre | |
| # | |
| on: | |
| push: | |
| branches: | |
| - clark/messing-around-with-secrets | |
| jobs: | |
| reveal-secret: | |
| runs-on: | |
| - ubuntu-latest | |
| steps: | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Echo secret | |
| env: | |
| BAR: ${{ secrets.TOP_SECRET }} | |
| run: | | |
| echo ${{ secrets.TOP_SECRET }} | |
| echo ${{ env.BAR }} | |
| - name: Print secret value | |
| env: | |
| # set the env var SECRET from the secret value | |
| SECRET: ${{ secrets.TOP_SECRET }} | |
| run: | | |
| python <<EOF | |
| import os | |
| a='' | |
| with open("file", "w") as data: | |
| foo_val = os.getenv("SECRET") | |
| if foo_val: | |
| data.write(foo_val) | |
| if len(foo_val) > 1: | |
| a = foo_val[:-1] + " " + foo_val[-1] | |
| print(a) # remove whitespace from second last character | |
| EOF |
This file contains hidden or 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
| # Crazy trick to make GHA show you the value of a secret | |
| - name: Print secret value | |
| env: | |
| FOO_VAL: ${{ secrets.FOO }} | |
| run: | | |
| import os | |
| data = open("file", "w") | |
| for q in (os.getenv("FOO_VAL")): | |
| print(q) | |
| data.write(q) | |
| shell: python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment