|
1 | 1 | name: "Copilot Setup Steps" |
2 | 2 |
|
3 | | -# Automatically run the setup steps when they are changed to allow for easy validation, and |
4 | | -# allow manual testing through the repository's "Actions" tab |
5 | 3 | on: |
6 | 4 | workflow_dispatch: |
7 | 5 |
|
8 | 6 | permissions: |
9 | 7 | id-token: write |
10 | 8 | contents: read |
11 | | - issues: write |
12 | 9 |
|
13 | 10 | jobs: |
14 | | - # The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot. |
15 | 11 | copilot-setup-steps: |
16 | 12 | runs-on: ubuntu-latest |
17 | | - |
18 | | - # Set the permissions to the lowest permissions possible needed for your steps. |
19 | | - # Copilot will be given its own token for its operations. |
20 | 13 | permissions: |
21 | | - # If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete. |
22 | | - contents: write |
23 | 14 | id-token: write |
| 15 | + contents: read |
| 16 | + environment: copilot # Must be exactly 'copilot' (lowercase) to match federated credential |
24 | 17 |
|
25 | | - # You can define any steps you want, and they will run before the agent starts. |
26 | | - # If you do not check out your code, Copilot will do this for you. |
27 | 18 | steps: |
28 | | - - name: Checkout code |
29 | | - uses: actions/checkout@v5 |
30 | | - |
31 | | - - name: Debug - Check if secrets are accessible |
32 | | - run: | |
33 | | - echo "Checking if secrets are set..." |
34 | | - |
35 | | - ERROR_COUNT=0 |
36 | | - |
37 | | - if [ -z "${{ secrets.ARM_CLIENT_ID }}" ]; then |
38 | | - echo "ERROR: ARM_CLIENT_ID is empty or not set" |
39 | | - ERROR_COUNT=$((ERROR_COUNT + 1)) |
40 | | - else |
41 | | - echo "✓ ARM_CLIENT_ID is set" |
42 | | - fi |
43 | | - |
44 | | - if [ -z "${{ secrets.ARM_TENANT_ID }}" ]; then |
45 | | - echo "ERROR: ARM_TENANT_ID is empty or not set" |
46 | | - ERROR_COUNT=$((ERROR_COUNT + 1)) |
47 | | - else |
48 | | - echo "✓ ARM_TENANT_ID is set" |
49 | | - fi |
50 | | - |
51 | | - if [ -z "${{ secrets.ARM_SUBSCRIPTION_ID }}" ]; then |
52 | | - echo "ERROR: ARM_SUBSCRIPTION_ID is empty or not set" |
53 | | - ERROR_COUNT=$((ERROR_COUNT + 1)) |
54 | | - else |
55 | | - echo "✓ ARM_SUBSCRIPTION_ID is set" |
56 | | - fi |
57 | | - |
58 | | - if [ $ERROR_COUNT -gt 0 ]; then |
59 | | - echo "" |
60 | | - echo "FATAL: $ERROR_COUNT required secret(s) missing." |
61 | | - echo "Please verify secrets are configured as Repository secrets (not environment secrets)." |
62 | | - echo "Go to: Settings → Secrets and variables → Actions → Repository secrets" |
63 | | - exit 1 |
64 | | - fi |
65 | | - |
66 | | - echo "" |
67 | | - echo "All required secrets are present. Proceeding with Azure login..." |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
68 | 21 |
|
69 | | - # Get OIDC token and login to Azure using federated identity |
70 | | - - name: Azure CLI Login with Federated Identity |
| 22 | + - name: Azure login |
71 | 23 | uses: azure/login@v2 |
72 | 24 | with: |
73 | | - client-id: ${{ secrets.ARM_CLIENT_ID }} |
74 | | - tenant-id: ${{ secrets.ARM_TENANT_ID }} |
75 | | - subscription-id: ${{ secrets.ARM_SUBSCRIPTION_ID }} |
76 | | - enable-AzPSSession: false |
| 25 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 26 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 27 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
77 | 28 |
|
78 | | - - name: Verify and persist Azure authentication |
| 29 | + - name: Verify Azure access |
79 | 30 | run: | |
80 | | - echo "Verifying Azure authentication..." |
81 | | - az account show |
82 | | - az group list --output table |
83 | | - |
84 | | - # Verify the Azure config directory exists and has auth tokens |
85 | | - ls -la ~/.azure/ |
86 | | - |
87 | | - echo "Azure CLI authentication successful!" |
88 | | - echo "Auth tokens are cached in ~/.azure/ and will persist for this runner session" |
89 | | - echo "Copilot will use these cached credentials" |
| 31 | + echo "Successfully authenticated to Azure!" |
90 | 32 | az account show |
91 | 33 | az group list --output table |
0 commit comments