|
28 | 28 | using: composite |
29 | 29 |
|
30 | 30 | steps: |
31 | | - - name: Dump GitHub context |
32 | | - shell: bash |
33 | | - run: | |
34 | | - cat << EOF |
35 | | - ${{ toJSON(github) }} |
36 | | - EOF |
37 | | - exit 1 |
38 | | -
|
39 | 31 | - name: Setup node |
40 | 32 | if: inputs.include-repository == 'true' |
41 | 33 | uses: actions/setup-node@v4 |
@@ -106,72 +98,96 @@ runs: |
106 | 98 | pandoc-spec |
107 | 99 | fi |
108 | 100 | |
109 | | - if [[ "${{ inputs.include-branches }}" == "true" ]] |
110 | | - then |
111 | | - pages_url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url') |
112 | | - |
113 | | - echo "Pages URL: $pages_url" |
114 | | - |
115 | | - # Get and unzip GitHub Pages archive. |
116 | | - curl -s $pages_url/_pages.zip -o _pages.zip |
117 | | - if [[ $? -eq 0 ]] |
118 | | - then |
119 | | - unzip -qq _pages.zip -d _pages |
120 | | - rm _pages.zip |
121 | | - else |
122 | | - # First time including branches. Treat current content as default branch; will be fixed on next push to default branch. |
123 | | - cp -r "${{ inputs.pages-path }}" _pages/ |
124 | | - fi |
125 | | -
|
126 | | - cd _pages |
127 | | - |
128 | | - if [[ -d _branch ]] |
129 | | - then |
130 | | - cd _branch |
| 101 | + - name: Merge branches |
| 102 | + if: inputs.include-pages == 'true' && inputs.include-branches == 'true' && github.ref_type == 'branch' |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + # Exit codes are handled by script. |
| 106 | + set +e |
131 | 107 | |
132 | | - BRANCHES=$(git branch --remotes --format=%\(refname:lstrip=-1\)) |
| 108 | + host_name=$(echo "${{ github.event.repository.owner.name }}.github.io" | tr "[:upper:]" "[:lower:]") |
| 109 | + repository_name="${{ github.event.repository.name }}" |
| 110 | + lower_repository_name=$(echo "$repository_name" | tr "[:upper:]" "[:lower:]") |
133 | 111 | |
134 | | - ls | while read -r branch |
135 | | - do |
136 | | - # Check than branch still exists. |
137 | | - echo "BRANCHES" | grep -q "^$branch$" |
| 112 | + if [[ "$lower_repository_name" == "host_name" ]] |
| 113 | + then |
| 114 | + pages_url="https://$host_name" |
| 115 | + else |
| 116 | + pages_url="https://$host_name/$repository_name" |
| 117 | + fi |
138 | 118 | |
139 | | - if [[ $? -ne 0 ]] |
140 | | - then |
141 | | - # Branch no longer exists; delete from GitHub Pages. |
142 | | - rm -rf "$branch" |
143 | | - fi |
144 | | - done |
| 119 | + echo "Pages URL: $pages_url" |
145 | 120 | |
146 | | - cd .. |
147 | | - else |
148 | | - mkdir _branch |
149 | | - fi |
| 121 | + ls -l |
150 | 122 | |
151 | | - branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} |
| 123 | + # Get and unzip GitHub Pages archive. |
| 124 | + curl -s $pages_url/_pages.zip -o _pages.zip |
| 125 | + if [[ $? -eq 0 ]] |
| 126 | + then |
| 127 | + unzip -qq _pages.zip -d _pages |
| 128 | + rm _pages.zip |
| 129 | + else |
| 130 | + # First time including branches. Treat current content as default branch; will be fixed on next push to default branch. |
| 131 | + cp -r "${{ inputs.pages-path }}" _pages/ |
| 132 | + fi |
| 133 | +
|
| 134 | + ls -l |
152 | 135 | |
153 | | - echo "Branch: $branch" |
| 136 | + cd _pages |
154 | 137 | |
155 | | - if [[ "$branch" == "${{ inputs.default-branch }}" ]] |
156 | | - then |
157 | | - # Move entire _branch directory. |
158 | | - mv _branch "../${{ inputs.pages-path }}/_branch" |
159 | | - else |
160 | | - # Remove previous branch content and replace with newly generated content. |
161 | | - rm -rf "_branch/$branch" |
162 | | - mv "../${{ inputs.pages-path }}/*" "_branch/$branch/" |
| 138 | + ls -l |
163 | 139 | |
164 | | - # Move consolidated directory into place. |
165 | | - mv * "../${{ inputs.pages-path }}/" |
166 | | - fi |
| 140 | + if [[ -d _branch ]] |
| 141 | + then |
| 142 | + cd _branch |
| 143 | + |
| 144 | + BRANCHES=$(git branch --remotes --format=%\(refname:lstrip=-1\)) |
167 | 145 | |
168 | | - cd "../${{ inputs.pages-path }}/" |
| 146 | + echo $BRANCHES |
| 147 | + |
| 148 | + ls | while read -r branch |
| 149 | + do |
| 150 | + # Check than branch still exists. |
| 151 | + echo "BRANCHES" | grep -q "^$branch$" |
| 152 | + |
| 153 | + if [[ $? -ne 0 ]] |
| 154 | + then |
| 155 | + # Branch no longer exists; delete from GitHub Pages. |
| 156 | + rm -rf "$branch" |
| 157 | + fi |
| 158 | + done |
| 159 | + |
| 160 | + cd .. |
| 161 | + else |
| 162 | + mkdir _branch |
| 163 | + fi |
169 | 164 | |
170 | | - zip -q -r ../_pages . |
171 | | - mv ../_pages.zip . |
| 165 | + ls -l |
| 166 | + |
| 167 | + branch=${{ github.ref_name }} |
172 | 168 | |
173 | | - cd .. |
| 169 | + echo "Branch: $branch" |
| 170 | + echo "Default: ${{ inputs.default-branch }}" |
| 171 | + |
| 172 | + if [[ "$branch" == "${{ inputs.default-branch }}" ]] |
| 173 | + then |
| 174 | + # Move entire _branch directory. |
| 175 | + mv _branch "../${{ inputs.pages-path }}/_branch" |
| 176 | + else |
| 177 | + # Remove previous branch content and replace with newly generated content. |
| 178 | + rm -rf "_branch/$branch" |
| 179 | + mv "../${{ inputs.pages-path }}"/* "_branch/$branch/" |
| 180 | + |
| 181 | + # Move consolidated directory into place. |
| 182 | + mv * "../${{ inputs.pages-path }}/" |
174 | 183 | fi |
| 184 | + |
| 185 | + cd "../${{ inputs.pages-path }}/" |
| 186 | + |
| 187 | + zip -q -r ../_pages . |
| 188 | + mv ../_pages.zip . |
| 189 | + |
| 190 | + cd .. |
175 | 191 |
|
176 | 192 | - name: Configure GitHub Pages |
177 | 193 | if: inputs.include-pages == 'true' |
|
0 commit comments