Skip to content

Publish the Code App with the Power Apps CLI, per Microsoft's guidance for service principals - #21

Merged
kippolitov merged 1 commit into
mainfrom
fix/code-app-push-with-pa-cli
Oct 6, 2026
Merged

kippolitov merged 1 commit into
mainfrom
fix/code-app-push-with-pa-cli

Conversation

@kippolitov

Copy link
Copy Markdown
Owner

Why

microsoft/PowerAppsCodeApps#394 (the HTTP 500 from pac code push under a service principal) was closed on 2026-08-19 with official guidance, now documented in Publish Power Apps code apps with a service principal:

  • a service principal needs edit access to the app itself; environment roles are not enough;
  • the app's owner grants that once with pa app share;
  • updates are published with pa app push --non-interactive, using the npm-based Power Apps CLI, not the PAC CLI.

This pipeline has been publishing with pac code push --solutionName MedTrackSolution, a workaround found in that issue's comments. This change moves it to the documented path.

What changes

  • scripts/deploy/deploy-app.ps1 runs pa app push --non-interactive. It signs the CLI in as the service principal through the PA_CLI_* environment variables, which it sets from the existing PP_CLIENT_ID, PP_CLIENT_SECRET and PP_TENANT_ID secrets. No new secrets or variables.
  • @microsoft/power-apps-cli is pinned at 1.2.0 as a dev dependency, so npm ci installs it with a locked integrity hash and the script never downloads another version.
  • deploy.reusable.yml (used by deploy-dev) and promote-prod.yml: the "Authenticate to Power Platform" step (pac auth create) is removed and the three secrets are passed to "Deploy Code App".
  • scripts/deploy/auth.ps1 is deleted; nothing else used the pac auth profile.
  • The local npm run build script still uses pac code push under the developer's own sign-in. Only the pipeline is affected.

Required before merging

deploy-dev runs on merge, and its "Deploy Code App" step will fail until the app is shared. As of 2026-10-05 neither service principal has a permission on its environment's app; only the owner does. The owner runs, once per environment, from a folder whose power.config.json points at that environment's app:

npx pa auth login
npx pa app share --principal <enterprise-application-object-id> --access edit
  • dev app → the dev service principal
  • production app → the production service principal (needed before the next "Promote to Production")

Testing

  • Lint, the 83 tests and the CI build pass with the new dependency. The lockfile change adds only the CLI itself.
  • The script fails with a clear message when a secret is missing, and the pinned CLI resolves without a download.
  • Not tested: a real publish as the service principal. That needs the pipeline's secrets and the app share above, so the first deploy-dev run after merging is the test. If it fails, reverting this commit restores the previous method.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 5, 2026 21:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The real service-principal publish remains untested, required app permissions are absent, and the current implementation plan is inconsistent with the new deployment path.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Migrates CI/CD Code App publishing from PAC to Microsoft’s service-principal-supported Power Apps CLI flow.

Changes:

  • Adds pinned pa app push --non-interactive deployment.
  • Passes service-principal credentials directly to deployment steps.
  • Updates deployment documentation and removes obsolete PAC authentication.
File Description
README.md Documents one-time app sharing.
package.json Pins the Power Apps CLI.
package-lock.json Locks CLI dependencies.
.github/​workflows/​deploy.reusable.yml Updates development deployment authentication.
.github/​workflows/​promote-prod.yml Updates production deployment authentication.
scripts/​deploy/​deploy-app.ps1 Implements noninteractive pa publishing.
scripts/​deploy/​auth.ps1 Removes obsolete PAC authentication.
scripts/​deploy/​migrate-data.ps1 Updates authentication commentary.
scripts/​ci/​render-power-config.ps1 Updates publishing documentation.
specs/​003-github-actions-cicd/​tasks.md Records the deployment migration.
specs/​003-github-actions-cicd/​contracts/​deploy.contract.md Updates the deployment contract.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +321 to +324
- `scripts/deploy/deploy-app.ps1` runs `pa app push --non-interactive` from `@microsoft/power-apps-cli`, pinned at 1.2.0 as a dev dependency so `npm ci` installs it with a locked integrity hash. It replaces `pac --log-to-console code push --solutionName MedTrackSolution`, the workaround from the section above.
- `deploy.reusable.yml` and `promote-prod.yml`: the "Authenticate to Power Platform" step (`pac auth create`) is removed, and the three service principal secrets are passed to "Deploy Code App" instead.
- `scripts/deploy/auth.ps1` is deleted: nothing else used the `pac auth` profile. The `PAC_CLI_SPN_SECRET` workaround it carried is no longer needed.
- The local `build` script (`pac code push` under the developer's own sign-in) is unchanged.
microsoft/PowerAppsCodeApps#394 was closed with official guidance: a
service principal needs edit access to the app itself, granted once by
the app's owner, and must publish with the npm-based Power Apps CLI,
not the PAC CLI.

- deploy-app.ps1 runs `pa app push --non-interactive`, signed in as the
  service principal through PA_CLI_* environment variables; replaces
  `pac code push --solutionName`
- @microsoft/power-apps-cli pinned at 1.2.0 as a dev dependency
- deploy.reusable.yml, promote-prod.yml: drop the `pac auth create`
  step and pass the service principal secrets to "Deploy Code App"
- remove scripts/deploy/auth.ps1, now unused
- README and spec 003 docs describe the one-time app share

Not yet run in the pipeline. The app must be shared with each
environment's service principal before the next deploy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kippolitov
kippolitov force-pushed the fix/code-app-push-with-pa-cli branch from 95af9a2 to ef9b025 Compare October 6, 2026 02:50
@kippolitov
kippolitov merged commit 5b58192 into main Oct 6, 2026
1 check passed
@kippolitov
kippolitov deleted the fix/code-app-push-with-pa-cli branch October 6, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants