# Version — which version of a workflow is running, and which file declares it

> `<Wf>.Version` is the number of the app version the code runs in — the same number a migration header names (`migration OrderFlow v6 -> v7`) and the version a new run pins. `<Wf>.Graph.SourceFile` is the file that declares the workflow. Together they let a page say "OrderFlow v7, declared in workflows/order-flow.osy".

<!-- id: workflow-version · area: workflow · stability: preview · html: https://osysharp.com/reference/workflow/version/ -->

## Summary        {#summary}
**`<Wf>.Version`** answers *"which version of this process is running?"* with an `int`: the **app version** the
code is running in. It is the number a workflow migration names — `migration OrderFlow v6 -> v7` moves runs from the
sixth version of the app to the seventh — and the version every run started now is pinned to.

```osy syntax
int v = OrderFlow.Version;               // 7
string? file = OrderFlow.Graph.SourceFile; // "workflows/order-flow.osy"
```

## Signature      {#signature}
```osy syntax
<Wf>.Version -> int                 // the app version the code runs in; 1 for an app on its first version
<Wf>.Graph.SourceFile -> string?    // the file that declares the workflow, its path from the app root
```

## Description    {#description}

### Why the app's version, and not the workflow's own   {#why}
A workflow has no version of its own that moves: every app version is compiled **fresh**, so the workflow's revision
row says `1` in every version. The platform's one idiom for "which version of a workflow" is therefore the app
version — the number migrations are written against ([Migrating runs that are still in flight](https://osysharp.com/reference/workflow/migration/)). Two workflows in the same app answer
the same number; the number changes when the app is published, whether or not that workflow changed.

### It is a server read   {#server}
The version is a fact about where the code runs, not about the declaration, so `<Wf>.Version` is answered on the
server (it costs no database statement). Read it in a function, or in a `live var`, like any other server value. The
workflow name is checked at compile time: `NoSuchFlow.Version` is an error, not a zero.

Code running a run that was started on an **earlier** version still executes in that version, and reads that
version's number.

### SourceFile   {#source-file}
`<Wf>.Graph.SourceFile` is set when the compiler builds the graph, like the rest of [Graph — every state and every transition of a workflow](https://osysharp.com/reference/workflow/graph/), so it names
the file of the version that is running and costs nothing. It is the path from the app root
(`workflows/order-flow.osy`), not just the file name — see [Graph — every state and every transition of a workflow](https://osysharp.com/reference/workflow/graph/). It is null for a workflow that has no file.

## Examples       {#examples}
```osy title="a workflow's version and its file, read in a test" test app=workflow-version
using Osysharp.Workflow;

enum JobStatus { Working, Done }

entity Job {
  [Required, MaxLength(80)] string Title;
  JobStatus Status = JobStatus.Working;
}

workflow JobFlow {
  Tracks    = Job.Status;
  Autostart = false;
  Initial   = Working;
  event Finish();
  state Working { on Finish { goto Done; } }
  terminal success Done { }
}

[Test]
void a_new_app_is_on_its_first_version_and_the_workflow_names_its_file() {
  Assert.Equal(1, JobFlow.Version);
  Assert.True(JobFlow.Graph.SourceFile != null);
}
```

## See also       {#see-also}
- [Migrating runs that are still in flight](https://osysharp.com/reference/workflow/migration/) — `migration Wf vN -> vM`, the numbers this one is
- [Graph — every state and every transition of a workflow](https://osysharp.com/reference/workflow/graph/) — the rest of the declaration as a value
- [Workflow.Current (which run is this code in?)](https://osysharp.com/reference/workflow/run-facts/) — facts about one run
