Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Deploy

# Manual on purpose: a push to main should not move an app that workspaces are
# relying on. Run it from the Actions tab and pick the environment; optionally
# install the app on a workspace, or upgrade it there after a scope change.
# A deploy without a scope change reaches existing installations on its own.
#
# Configuration, set once in the repository settings:
# vars.FORGE_APP_ID ari:cloud:ecosystem::app/<uuid>, printed by `forge register`
# secrets.FORGE_EMAIL the Atlassian account's email
# secrets.FORGE_API_TOKEN id.atlassian.com > Security > API tokens
#
# manifest.yml keeps a placeholder app id, so a fork cannot deploy over the
# real app; this workflow writes the real one in before deploying.
on:
workflow_dispatch:
inputs:
environment:
description: Forge environment
type: choice
options: [development, staging, production]
default: development
install:
description: After deploying, install on the workspace (first time) or upgrade it (new scopes)
type: choice
options: [none, install, upgrade]
default: none
workspace:
description: Bitbucket workspace for install or upgrade, e.g. bitbucket.org/my-workspace
type: string
default: ''

permissions:
contents: read

# One deploy at a time per environment, queued rather than raced.
concurrency:
group: deploy-${{ inputs.environment }}
cancel-in-progress: false

jobs:
deploy:
runs-on: ubuntu-latest
# A command waiting on a prompt would otherwise sit until GitHub's 6-hour limit.
timeout-minutes: 30
env:
FORGE_USAGE_ANALYTICS: 'false'
# FORGE_EMAIL and FORGE_API_TOKEN go only to the steps that talk to
# Atlassian, so dependency install scripts never see the token.
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Use Node.js 24.x
# The Forge CLI rejects Node 22.23.1, which is what '22.x' resolves to.
# The function itself still runs on Node 22 (manifest.yml).
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24.x
cache: 'npm'

- name: Check the inputs
env:
INSTALL: ${{ inputs.install }}
WORKSPACE: ${{ inputs.workspace }}
run: |
if [ "$INSTALL" != none ] && [ -z "$WORKSPACE" ]; then
echo "::error::Install or upgrade needs a workspace, e.g. bitbucket.org/my-workspace."
exit 1
fi

- name: Install the Forge CLI
# keytar, a native module of the CLI, builds against libsecret.
run: |
sudo apt-get update && sudo apt-get install -y libsecret-1-dev
npm install -g @forge/cli@16.0.0
forge settings set usage-analytics false

- name: Install dependencies
run: npm ci

- name: Write the app id into manifest.yml
env:
APP_ID: ${{ vars.FORGE_APP_ID }}
run: |
if ! printf '%s' "$APP_ID" | grep -Eq '^ari:cloud:ecosystem::app/[0-9a-fA-F-]{36}$'; then
echo "::error::Set the repository variable FORGE_APP_ID to the ari that 'forge register' printed."
exit 1
fi
sed -i -E "s|^ id: ari:cloud:ecosystem::app/.*$| id: ${APP_ID}|" manifest.yml
grep -q "^ id: ${APP_ID}$" manifest.yml

- name: Build the deploy package
run: npm run build

- name: Forge lint
env:
FORGE_EMAIL: ${{ secrets.FORGE_EMAIL }}
FORGE_API_TOKEN: ${{ secrets.FORGE_API_TOKEN }}
run: forge lint

- name: Forge deploy
env:
FORGE_EMAIL: ${{ secrets.FORGE_EMAIL }}
FORGE_API_TOKEN: ${{ secrets.FORGE_API_TOKEN }}
ENVIRONMENT: ${{ inputs.environment }}
run: forge deploy --environment "$ENVIRONMENT" --non-interactive

- name: Forge install
if: inputs.install != 'none'
env:
FORGE_EMAIL: ${{ secrets.FORGE_EMAIL }}
FORGE_API_TOKEN: ${{ secrets.FORGE_API_TOKEN }}
ENVIRONMENT: ${{ inputs.environment }}
INSTALL: ${{ inputs.install }}
WORKSPACE: ${{ inputs.workspace }}
run: |
set -- --environment "$ENVIRONMENT" --product Bitbucket --site "$WORKSPACE" --confirm-scopes --non-interactive
if [ "$INSTALL" = upgrade ]; then set -- "$@" --upgrade; fi
forge install "$@"
44 changes: 30 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,41 @@ what the checks report, so it is bumped by hand.

## Deploying

1. Install the Forge CLI and log in with an Atlassian API token:
`npm install -g @forge/cli` then `forge login`.
2. Register the app, from this directory: `forge register "Commit Check"`.
This writes the real `app.id` into `manifest.yml`; commit that change.
3. Install the dependencies, build, and deploy: `npm ci`, `npm run build`,
then `forge deploy`.
The package is built by hand (`app.package.bundler: manual@2026`, a Forge
preview feature), because Forge's default bundler cannot ship Pyodide's
WebAssembly.
4. Install in a test workspace: `forge install`, choosing Bitbucket and the
workspace.
5. In Bitbucket, a workspace admin turns on **Custom merge checks** in the
Deploys run from GitHub Actions: the **Deploy** workflow, started by hand
from the Actions tab. It builds the package, runs `forge lint` and
`forge deploy`, and can then install the app on a workspace.

Once, before the first deploy:

1. Register the app with the Forge CLI (`npm install -g @forge/cli`,
`forge login`, then `forge register "Commit Check"` in this directory).
It prints the app id (`ari:cloud:ecosystem::app/...`) and writes it into
your local `manifest.yml`. Do not commit that line: the repository keeps a
placeholder, so a fork cannot deploy over the real app.
2. In the repository's **Settings > Secrets and variables > Actions**, add the
variable `FORGE_APP_ID` (the app id) and the secrets `FORGE_EMAIL` and
`FORGE_API_TOKEN` (an Atlassian API token from
[id.atlassian.com](https://id.atlassian.com/manage-profile/security/api-tokens)).

Each deploy:

1. Run **Deploy** with the environment (development, staging or production).
Code changes reach existing installations on their own.
2. The first time in an environment, set **install** to `install` and
**workspace** to `bitbucket.org/<workspace>`. After a change to the
manifest's scopes, run it with `upgrade` so installations accept them.
3. In Bitbucket, a workspace admin turns on **Custom merge checks** in the
workspace settings; then a repository admin enables **Commit Check** (and
**Commit Check merge message** for squash merges) under the repository's
merge checks. On Premium, tick **Required** to block merges.
6. Open a pull request and push a commit. `forge logs` shows
4. Open a pull request and push a commit. `forge logs` shows
`Merge check {repo}#1 (on-code-pushed): pass`.

For production, `forge deploy -e production` and `forge install -e production`.
The package is built by hand (`app.package.bundler: manual@2026`, a Forge
preview feature), because Forge's default bundler cannot ship Pyodide's
WebAssembly. To deploy from a laptop instead: `npm ci`, `npm run build`,
`forge deploy`, `forge install`.

Atlassian lists Bitbucket Forge apps on the Marketplace as information only
(no install button, no billing); installs go through the app's distribution
link in the developer console. The Forge CLI's eligibility check shows whether the app
Expand Down
3 changes: 2 additions & 1 deletion manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ permissions:
- read:pullrequest:bitbucket
- read:repository:bitbucket
app:
# Written by `forge register`.
# A placeholder: the Deploy workflow writes the real id from the
# FORGE_APP_ID repository variable (README.md, Deploying).
id: ari:cloud:ecosystem::app/00000000-0000-0000-0000-000000000000
runtime:
name: nodejs22.x
Expand Down