Skip to content

Commit 541fb6e

Browse files
authored
Add workflow to test publish-technical-documentation-release workflow (#917)
* Add workflow to test publish-technical-documentation-release workflow Signed-off-by: Jack Baldry <[email protected]> * Check out the HEAD of branch before testing the build Signed-off-by: Jack Baldry <[email protected]> * Only care if the event is a tag event Signed-off-by: Jack Baldry <[email protected]> * Strip tag prefix from github.ref Signed-off-by: Jack Baldry <[email protected]> * Use Bash regular expression syntax Signed-off-by: Jack Baldry <[email protected]> * Add more script output Signed-off-by: Jack Baldry <[email protected]> * Add more script output Signed-off-by: Jack Baldry <[email protected]> * Fix branch trigger glob * Add testing instructions as code comments in the workflow --------- Signed-off-by: Jack Baldry <[email protected]>
1 parent 353b1a7 commit 541fb6e

File tree

3 files changed

+66
-31
lines changed

3 files changed

+66
-31
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# To use this workflow to test the publish-technical-documentation-release action:
2+
# 1. Create a branch `test/publish-technical-documentation/v<MAJOR>.<MINOR>.x`.
3+
# 2. Iterate on the workflow or action.
4+
# 3a. To test push events, push the branch.
5+
# 3b. To test tag events, tag the branch with `test/publish-technical-documentation/v<MAJOR>.<MINOR>.<PATCH>`.
6+
# 4. Check the workflow output in https://github.com/grafana/writers-toolkit/actions.
7+
8+
name: test-publish-technical-documentation-release
9+
10+
on:
11+
push:
12+
branches:
13+
- test/publish-technical-documentation-release/v[0-9]+.[0-9]+.x
14+
tags:
15+
- test/publish-technical-documentation-release/v[0-9]+.[0-9]+.[0-9]+
16+
workflow_dispatch:
17+
jobs:
18+
sync:
19+
if: github.repository == 'grafana/writers-toolkit'
20+
permissions:
21+
contents: read
22+
id-token: write
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
- uses: ./publish-technical-documentation-release
29+
with:
30+
release_tag_regexp: "^test/publish-technical-documentation-release/v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
31+
release_branch_regexp: "^test/publish-technical-documentation-release/v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.x$"
32+
release_branch_with_patch_regexp: "^test/publish-technical-documentation-release/v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
33+
website_branch: test/publish-technical-documentation-release
34+
website_directory: content/docs/publish-technical-documetation-release
35+
version_suffix: ""

publish-technical-documentation-release/action.yaml

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ inputs:
4141
source_directory:
4242
default: docs/sources
4343
description: Path to source directory, relative to the project root, to sync documentation from.
44+
website_branch:
45+
default: master
46+
description: |
47+
Website repository branch to sync the documentation to.
4448
website_directory:
4549
description: |
4650
Website directory to sync the documentation to.
@@ -54,6 +58,25 @@ inputs:
5458
runs:
5559
using: composite
5660
steps:
61+
- name: Switch to HEAD of branch for tags
62+
# Tags aren't necessarily made to the HEAD of the branch.
63+
# The documentation to be published is always on the HEAD of the branch.
64+
if: github.ref_type == 'tag'
65+
env:
66+
GITHUB_REF: ${{ github.ref }}
67+
RELEASE_BRANCH_REGEXP: ${{ inputs.release_branch_regexp }}
68+
run: |
69+
branch="$(./publish-technical-documentation-release/determine-release-branch "${RELEASE_BRANCH_REGEXP}" "${GITHUB_REF}")"
70+
71+
if [[ -z "${branch}" ]]; then
72+
echo "No release branch found for tag ${GITHUB_REF} matching ${RELEASE_BRANCH_REGEXP}. Exiting."
73+
74+
exit 1
75+
fi
76+
77+
git switch --detach "origin/${branch}"
78+
shell: bash
79+
5780
- name: Build website
5881
shell: bash
5982
run: |
@@ -86,48 +109,20 @@ runs:
86109
run: npm install --production --prefix ./actions
87110
shell: bash
88111

89-
- name: Determine if there is a matching release tag
90-
id: has-matching-release-tag
91-
uses: ./actions/has-matching-release-tag
92-
with:
93-
ref_name: ${{ github.ref_name }}
94-
release_branch_regexp: ${{ inputs.release_branch_regexp }}
95-
release_branch_with_patch_regexp: ${{ inputs.release_branch_with_patch_regexp }}
96-
release_tag_regexp: ${{ inputs.release_tag_regexp }}
97-
98112
- name: Determine technical documentation version
99113
if: steps.has-matching-release-tag.outputs.bool == 'true'
100114
uses: ./actions/docs-target
101115
id: target
102116
with:
103117
ref_name: ${{ github.ref_name }}
104118

105-
- name: Switch to HEAD of version branch for tags
106-
# Tags aren't necessarily made to the HEAD of the version branch.
107-
# The documentation to be published is always on the HEAD of the release branch.
108-
if: steps.has-matching-release-tag.outputs.bool == 'true' && github.ref_type == 'tag'
109-
env:
110-
GITHUB_REF: ${{ github.ref }}
111-
RELEASE_BRANCH_REGEXP: ${{ inputs.release_branch_regexp }}
112-
run: |
113-
branch="$(./publish-technical-documentation-release/determine-release-branch "${RELEASE_BRANCH_REGEXP}" "${GITHUB_REF}")"
114-
115-
if [[ -z "${branch}" ]]; then
116-
echo "No release branch found for tag ${GITHUB_REF} matching ${RELEASE_BRANCH_REGEXP}. Exiting."
117-
118-
exit 1
119-
fi
120-
121-
git switch --detach "origin/${branch}"
122-
shell: bash
123-
124119
- name: Sync to the website repository (release)
125120
if: steps.has-matching-release-tag.outputs.bool == 'true'
126121
uses: ./.github/actions/website-sync
127122
id: publish-release
128123
with:
129124
repository: grafana/website
130-
branch: master
125+
branch: ${{ inputs.website_branch }}
131126
host: github.com
132127
github_pat: grafanabot:${{ env.PUBLISH_TO_WEBSITE_TOKEN }}
133128
source_folder: ${{ inputs.source_directory }}

publish-technical-documentation-release/determine-release-branch

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ if [[ $# -ne 2 ]]; then
2121
fi
2222

2323
BRANCH_REGEXP="$1"
24-
TAG="$2"
24+
TAG="${2#refs/tags/}"
2525

26-
for branch in $(git branch -a --contains "tags/${TAG}"); do
26+
contains="$(git branch -a --contains "tags/${TAG}")"
27+
for branch in ${contains}; do
2728
branch="${branch#remotes/origin/}";
29+
echo "Checking branch ${branch} against ${BRANCH_REGEXP}." >&2
2830

2931
if [[ "${branch}" =~ ${BRANCH_REGEXP} ]]; then
3032
echo "${branch}";
@@ -33,4 +35,7 @@ for branch in $(git branch -a --contains "tags/${TAG}"); do
3335
fi;
3436
done
3537

38+
echo "No release branch found for tag ${TAG} matching ${BRANCH_REGEXP}. Exiting." >&2
39+
echo "Branches containing tag ${TAG}:" >&2
40+
echo "${contains}" >&2
3641
exit 1

0 commit comments

Comments
 (0)