This action builds and deploys a service on Valar. It waits until the deployment is live, fails the job if the build or the deployment fails, and reports the service's URL. It can also deploy a preview of every pull request.
It runs on Linux and macOS runners (x64 and ARM64) and needs nothing but curl and bash.
name: Deploy
on:
push:
branches: [main]
concurrency:
group: valar-deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
environment:
name: production
url: ${{ steps.valar.outputs.url }}
steps:
- uses: actions/checkout@v7
- id: valar
uses: valar/action@v3The project, service and build settings come from .valar.yml, which valar service init writes. The build log appears in the job log. The URL appears in the job summary and, through environment.url, on the commit and its pull request. The concurrency group lets one deploy finish before the next starts.
Without a token input, the action exchanges the job's GitHub identity token for a Valar token that acts as whoever added the trust policy, can only read and deploy the one service, and lasts an hour. The job needs permissions: id-token: write, and the project needs a trust policy that admits the job. Someone who manages the project adds it once, with the Valar CLI and a token created in the console, here for the workflow above saved as .github/workflows/deploy.yml:
valar trust add --project acme --service web \
--github-repo acme/web --environment production --workflow deploy.ymlThe policy pins the repository's and its owner's IDs, the workflow file and the push event, so other repositories, workflows and triggers do not match. A job that names an environment, like the one above, gets an identity token for the environment rather than the branch: protect the environment with deployment branch rules (Settings, Environments, production, Deployment branches), because GitHub issues that identity token to every job that names the environment, whatever its branch. A job without an environment needs --branch main in place of --environment production.
valar trust list shows a project's policies and valar trust remove <id> deletes one and revokes the tokens it issued. When no policy admits a job, the step fails and its log shows the identity token's claims to compare with valar trust list.
The installation must trust GitHub's identity tokens; on a self-hosted one, its operator sets this up. Without that, or to deploy from other CI systems, give the action a stored token instead:
- uses: valar/action@v3
with:
token: ${{ secrets.VALAR_TOKEN }}Create the token bound to the project with only read and deploy, valar token create github-deploy --project acme --scopes read,deploy, and store it as a repository or environment secret. It lasts 90 days by default; the job needs no id-token permission then.
| Input | Default | |
|---|---|---|
token |
Valar API token that can only read and deploy in the project (valar token create --project <project> --scopes read,deploy github-deploy), stored as a secret. Without it, the action exchanges the job's GitHub identity token under a trust policy, which needs permissions: id-token: write. |
|
audience |
the endpoint's origin | Audience of that identity token, such as https://api.valar.dev. Set it only if the installation's operator configured another one. |
endpoint |
https://api.valar.dev/v2 |
API of the Valar installation, for self-hosted Valar. |
project |
from .valar.yml |
Project to deploy to. |
service |
from .valar.yml |
Service to deploy. |
workdir |
. |
Directory to push. .valar.yml is looked up from here upwards. |
wait |
true |
Wait for the build and the deployment, and fail if either fails. With false the step ends once the build is submitted. |
deploy |
true |
With false the service is only built, for example to check pull requests. |
preview |
false |
Deploy pull request previews, see below. |
github-token |
github.token |
Token for the preview comment. |
timeout |
30m |
How long to wait for the build and the deployment together. |
cli-version |
4.11.0 |
Valar CLI release to run. The default release's binaries are verified against checksums in this action. |
| Output | |
|---|---|
build-id |
ID of the build. |
service |
Service that was deployed, when it was given as an input or is a preview. |
url |
Preferred URL of the service: a linked custom domain if there is one, else its own <project>-<service> domain. Empty without a deployment. |
With preview: true, a pull_request run deploys to the service <service>pr<number> instead, for example webpr42, and comments its URL on the pull request. The number comes from the run's ref, refs/pull/<number>/merge. When the pull request closes, the preview is disabled; when it reopens, it is enabled and deployed again.
name: Preview
on:
pull_request:
types: [opened, synchronize, reopened, closed]
concurrency:
group: valar-preview-${{ github.event.pull_request.number }}
permissions:
contents: read
pull-requests: write
id-token: write
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
if: github.event.action != 'closed'
- uses: valar/action@v3
with:
project: acme
service: web
preview: trueThe trust policy for previews names the prefix followed by *; each pull request may then deploy only its own preview:
valar trust add --project acme --service 'webpr*' --github-repo acme/web --pull-requests- Name the project and service in the inputs, because a closed pull request's run has no checkout to read
.valar.ymlfrom. - The action skips pull requests from forks, but don't rely on that check: it runs in the pull request's own copy of the workflow, which a fork can change. Public repositories give fork pull requests no secrets and no identity tokens. A private repository can give them both, through "Send write tokens to workflows from pull requests" and "Send secrets to workflows from pull requests" in its Actions settings. Then a stored token reaches the fork's code. What bounds an identity token is the trust policy: a preview policy admits a pull request only to its own
<service>pr<number>, and a branch or environment policy pins the subject, thepushevent and the workflow's ref, while a pull request's job carries thepull_requestevent and the pull request's ref. - Use
pull_request, neverpull_request_target, which would deploy a fork's code with your credentials. Without atoken, the action refuses to exchange identity tokens inpull_request_targetandworkflow_runruns. - Disabled previews stop running and answer 503. Valar can't delete services yet, so they remain in
valar service list. - Anyone who can push a branch to the repository can deploy a preview. Under a trust policy, it reaches only
<service>pr<number>and runs as that preview's own service account. With a stored token, it holds the same token as production deploys; keep previews in a project of their own if that matters.
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: valar/action@v3
with:
token: ${{ secrets.VALAR_TOKEN }}
deploy: falseThis check keeps a stored token: a trust policy that admitted pull requests to the service itself would let any of them deploy it, since deploy: false is only an input.
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
dir: [api, web]
steps:
- uses: actions/checkout@v7
- uses: valar/action@v3
with:
token: ${{ secrets.VALAR_TOKEN }}
workdir: ${{ matrix.dir }}Without a stored token, each service needs a trust policy of its own.
Set endpoint to your installation's API, such as https://api.example.com/v2. Without a token, the identity token is requested for the endpoint's origin, https://api.example.com, unless audience names another.
To run exactly the code you reviewed, pin the action to a commit:
- uses: valar/action@<commit sha> # v3.0.0v2 ran the Valar CLI 2.0.1, always against api.valar.dev, and finished as soon as the build was submitted, so failed builds left the job green. v3 takes the same token and workdir inputs. It waits for the deployment by default; set wait: false for the old behaviour.
Apache-2.0