forked from openhab/openhab-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_external_docs_reusable.yml
More file actions
134 lines (123 loc) · 5.48 KB
/
Copy pathfetch_external_docs_reusable.yml
File metadata and controls
134 lines (123 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Fetch Docs Reusable
# Generic action for fetching doc resources
# This action is meant to be called by a detailed action for a specific repository, defining the necessary parameters.
# This action is usually used to update stable documentation after the release of a new version from a specific repository.
on:
workflow_call:
inputs:
base_target_branch:
description: The branch to check out in the target repository. Defaults to `final-stable`.
default: final-stable
required: false
type: string
base_source_organization:
description: The organization or user that holds the base repository. Defaults to `openhab`.
default: openhab
required: false
type: string
base_source_repository:
description: The repository that holds the source resources to copy.
required: true
type: string
base_source_ref:
description: The branch or tag ref that holds the source resources to copy.
required: false
type: string
base_folder:
description: The folder that holds the resources in the target repository.
required: true
type: string
base_file:
description: The default file name to rename as if `doc_base_file` defined. Defaults to `readme.md`.
default: readme.md
required: false
type: string
doc_base_name:
description: The doc file name prefix for lookup options.
required: false
type: string
doc_base_dir:
description: The doc directory path that holds the source resources to copy. Defaults to `/docs`.
default: /docs
required: false
type: string
doc_base_file:
description: The doc default file to rename as `base_file`.
required: false
type: string
doc_exclude_pattern:
description: A file name or pattern to exclude from the .md copy step (e.g., `README.md` or `*_test.md`).
required: false
type: string
image_base_dir:
description: The image directory path that holds the image resources. Defaults to `/images`.
default: /images
required: false
type: string
has_images:
description: If doc has images. Defaults to `false`.
default: false
required: false
type: boolean
is_self_contained:
description: If doc is self-contained. Defaults to `true`.
default: true
required: false
type: boolean
jobs:
fetchDocs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.base_target_branch }}
- name: Checkout external repository
uses: actions/checkout@v6
with:
repository: ${{ inputs.base_source_organization }}/${{ inputs.base_source_repository }}
path: ./external_repositories/${{ inputs.base_source_repository }}
ref: ${{ inputs.base_source_ref }}
- name: Initialize doc folder structure
run: mkdir -vp "${{ inputs.base_folder }}${{ inputs.has_images && inputs.image_base_dir || '' }}"
# Remove existing doc resources if self-contained or doc file name prefix defined
- name: Remove existing doc resources
if: ${{ inputs.is_self_contained || inputs.doc_base_name }}
run: find $TARGET_DIR -iname "${{ inputs.doc_base_name }}*" -type f -exec rm -v {} \;
env:
TARGET_DIR: ${{ inputs.base_folder }}
- name: Copy latest doc resources
run: |
if [ -z "${{ inputs.doc_exclude_pattern }}" ]; then
find $SOURCE_DIR -maxdepth 1 -iname "${{ inputs.doc_base_name }}*.md" -type f -exec cp -v {} $TARGET_DIR \;
else
find $SOURCE_DIR -maxdepth 1 -iname "${{ inputs.doc_base_name }}*.md" -not -iname "${{ inputs.doc_exclude_pattern }}" -type f -exec cp -v {} $TARGET_DIR \;
fi
env:
SOURCE_DIR: ./external_repositories/${{ inputs.base_source_repository }}${{ inputs.doc_base_dir }}
TARGET_DIR: ${{ inputs.base_folder }}
# Rename doc default file if parameter defined
- name: Rename doc default file
if: ${{ inputs.doc_base_file }}
run: mv -v ${{ inputs.doc_base_file }} ${{ inputs.base_file }}
working-directory: ${{ inputs.base_folder }}
# Copy image resources if has images
- name: Copy latest image resources
if: ${{ inputs.has_images }}
run: rsync -av --include='*/' --include='*.png' --include='*.svg' --include='*.bmp' --exclude='*' --prune-empty-dirs $SOURCE_DIR $TARGET_DIR
env:
SOURCE_DIR: ./external_repositories/${{ inputs.base_source_repository }}${{ inputs.doc_base_dir }}${{ inputs.image_base_dir }}/
TARGET_DIR: ${{ inputs.base_folder }}${{ inputs.image_base_dir }}/
- name: Remove external repository files
run: rm -rf ./external_repositories
# Create an automated pull request, if the resulting branch is ahead of the `base-target-branch`
- name: Create pull request
uses: peter-evans/create-pull-request@v8
with:
commit-message: Automated ${{ inputs.base_source_repository }} Docs fetch
committer: openHAB Bot <info@openhab.org>
author: openHAB Bot <info@openhab.org>
branch: automated/fetch_${{ inputs.base_source_repository }}_docs
delete-branch: true
title: "[Automated] Fetch ${{ inputs.base_source_repository }} docs"
labels: automated_pr