# Scenario Book for Jira — GitHub Actions. # # Copy into .github/workflows/scenario-book.yml and copy scenario-book-sync.mjs anywhere in the repo. # Set the secrets listed in README.md under Settings → Secrets and variables → Actions. # # Two jobs on purpose. `sync` runs on a schedule and opens a pull request with what Jira changed; `push` # runs on every commit to the default branch. Keeping them apart is what stops the loop: a pull request that # merges Jira's changes would otherwise trigger a push of the files Jira just sent, which answers "unchanged" # but spends a call on every file to say so. name: Scenario Book on: schedule: # Every 15 minutes. Jira is the side people edit in, so this is how fast their changes reach the repo. - cron: '*/15 * * * *' push: branches: [main] workflow_dispatch: # One at a time. Two runs pushing the same project at once would each be told to wait by the rate limit, and # the second would fail a job over a file the first had already sent. concurrency: group: scenario-book cancel-in-progress: false jobs: pull-from-jira: if: github.event_name != 'push' runs-on: ubuntu-latest permissions: contents: write pull-requests: write steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: '20' - name: Pull Jira's feature files env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} SB_DIR: features run: node scenario-book-sync.mjs pull - name: Open a pull request if anything changed # A pull request rather than a commit straight to main: a scenario arriving from Jira is a change to # what the tests assert, and it goes through review like any other. uses: peter-evans/create-pull-request@v7 with: branch: scenario-book/from-jira title: 'Scenario Book: feature files from Jira' body: | Scenarios edited in Jira, pulled into the repository by Scenario Book. commit-message: 'Scenario Book: feature files from Jira' delete-branch: true push-to-jira: if: github.event_name == 'push' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: # The push sends the commit sha, so the shallow default is enough — but fetch the tip properly so # `git rev-parse HEAD` is the commit being pushed and not a merge commit Actions made. fetch-depth: 1 - uses: actions/setup-node@v4 with: node-version: '20' - name: Send the repo's feature files to Jira env: JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} SB_SYNC_KEY: ${{ secrets.SB_SYNC_KEY }} SB_PUSH_URL: ${{ secrets.SB_PUSH_URL }} SB_DIR: features run: node scenario-book-sync.mjs push # Add this to whichever job runs your tests, rather than as a job of its own: it needs the report file. # # - name: Upload the test results to Scenario Book # if: always() # a failing test run is the one you most want in Jira # env: # JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} # JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }} # JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} # JIRA_PROJECT: ${{ secrets.JIRA_PROJECT }} # SB_SYNC_KEY: ${{ secrets.SB_SYNC_KEY }} # SB_RESULTS_URL: ${{ secrets.SB_RESULTS_URL }} # SB_LABEL: github-actions # run: node scenario-book-sync.mjs results reports/cucumber.json