|
| 1 | +name: 1. Validate Secrets |
| 2 | +run-name: Validate Secrets |
| 3 | +on: [workflow_call, workflow_dispatch] |
| 4 | + |
| 5 | +jobs: |
| 6 | + validate: |
| 7 | + runs-on: macos-12 |
| 8 | + steps: |
| 9 | + # Checks-out the repo |
| 10 | + - name: Checkout Repo |
| 11 | + uses: actions/checkout@v3 |
| 12 | + |
| 13 | + # Validates the repo secrets |
| 14 | + - name: Validate Secrets |
| 15 | + run: | |
| 16 | + # Validate Secrets |
| 17 | + echo Validating Repository Secrets... |
| 18 | + |
| 19 | + # Validate TEAMID |
| 20 | + if [ -z "$TEAMID" ]; then |
| 21 | + failed=true |
| 22 | + echo "::error::TEAMID secret is unset or empty. Set it and try again." |
| 23 | + elif [ ${#TEAMID} -ne 10 ]; then |
| 24 | + failed=true |
| 25 | + echo "::error::TEAMID secret is set but has wrong length. Verify that it is set correctly and try again." |
| 26 | + fi |
| 27 | + |
| 28 | + # Validate GH_PAT |
| 29 | + if [ -z "$GH_PAT" ]; then |
| 30 | + failed=true |
| 31 | + echo "::error::GH_PAT secret is unset or empty. Set it and try again." |
| 32 | + elif [ "$(gh api -H "Accept: application/vnd.github+json" /repos/${{ github.repository_owner }}/Match-Secrets | jq --raw-output '.permissions.push')" != "true" ]; then |
| 33 | + failed=true |
| 34 | + echo "::error::GH_PAT secret is set but invalid or lacking appropriate privileges on the ${{ github.repository_owner }}/Match-Secrets repository. Verify that it is set correctly and try again." |
| 35 | + fi |
| 36 | + |
| 37 | + # Validate FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY |
| 38 | + if [ -z "$FASTLANE_ISSUER_ID" ] || [ -z "$FASTLANE_KEY_ID" ] || [ -z "$FASTLANE_KEY" ]; then |
| 39 | + failed=true |
| 40 | + [ -z "$FASTLANE_ISSUER_ID" ] && echo "::error::The FASTLANE_ISSUER_ID secret is unset or empty. Set it and try again." |
| 41 | + [ -z "$FASTLANE_KEY_ID" ] && echo "::error::The FASTLANE_KEY_ID secret is unset or empty. Set it and try again." |
| 42 | + [ -z "$FASTLANE_KEY" ] && echo "::error::The FASTLANE_KEY secret is unset or empty. Set it and try again." |
| 43 | + elif ! echo "$FASTLANE_KEY" | openssl pkcs8 -nocrypt >/dev/null; then |
| 44 | + failed=true |
| 45 | + echo "::error::The FASTLANE_KEY secret is set but invalid. Verify that it is set correctly and try again." |
| 46 | + elif ! fastlane validate_secrets; then |
| 47 | + failed=true |
| 48 | + echo "::error::Unable to create a valid authorization token for the App Store Connect API.\ |
| 49 | + Verify that the FASTLANE_ISSUER_ID, FASTLANE_KEY_ID, and FASTLANE_KEY secrets are set correctly and try again." |
| 50 | + fi |
| 51 | + |
| 52 | + # Validate MATCH_PASSWORD |
| 53 | + if [ -z "$MATCH_PASSWORD" ]; then |
| 54 | + failed=true |
| 55 | + echo "::error::The MATCH_PASSWORD secret is unset or empty. Set it and try again." |
| 56 | + fi |
| 57 | + |
| 58 | + # Exit unsuccessfully if secret validation failed. |
| 59 | + if [ $failed ]; then |
| 60 | + exit 2 |
| 61 | + fi |
| 62 | + shell: bash |
| 63 | + env: |
| 64 | + TEAMID: ${{ secrets.TEAMID }} |
| 65 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 66 | + FASTLANE_ISSUER_ID: ${{ secrets.FASTLANE_ISSUER_ID }} |
| 67 | + FASTLANE_KEY_ID: ${{ secrets.FASTLANE_KEY_ID }} |
| 68 | + FASTLANE_KEY: ${{ secrets.FASTLANE_KEY }} |
| 69 | + MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} |
| 70 | + GH_TOKEN: ${{ secrets.GH_PAT }} |
0 commit comments