Skip to content

Commit 5e3f32a

Browse files
Merge pull request #5 from TeachBooks/feat/1/actions-summaries
Actions summaries
2 parents 83948da + d8ba09f commit 5e3f32a

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

.github/workflows/deploy-book.yml

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
# Configuration variables may be set as explained here:
1111
# https://docs.github.com/en/actions/learn-github-actions/variables#creating-configuration-variables-for-a-repository
1212
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1314
# `main` as primary by default, advised to make it `published` to start using draft-publish-workflow
1415
PRIMARY_BRANCH: ${{ vars.PRIMARY_BRANCH != '' && vars.PRIMARY_BRANCH || 'main' }}
1516
# Space-separated list of alias-rules, e.g. 'draft:main alias:really-long-branch-name'
@@ -25,6 +26,7 @@ jobs:
2526
runs-on: ubuntu-latest
2627
outputs:
2728
branches: ${{ steps.set-branches.outputs.branches }}
29+
summary: ${{ steps.set-branches.outputs.summary }}
2830
permissions:
2931
contents: read
3032
steps:
@@ -35,16 +37,53 @@ jobs:
3537
- id: set-branches
3638
name: Set branches
3739
run: |
40+
# If all (*), query all remote branches
41+
# If not, read from env var
3842
if [ "$BRANCHES_TO_DEPLOY" == '*' ]; then
3943
branches=$(git branch -r | sed 's,\s*origin/,,g')
4044
else
4145
branches=$(echo "$BRANCHES_TO_DEPLOY" | tr ' ' '\n' | grep -E '\S')
4246
fi
47+
48+
{
49+
# Display raw/clean branch name versions in Actions Summary
50+
echo "### Branches deployed"
51+
## Table headers
52+
echo "| Branch :tanabata_tree: | Link :link: |"
53+
echo "| :--- | :--- |"
54+
} >> summary.md
55+
56+
## Fetch the GH Pages URL
57+
# https://stackoverflow.com/a/76354104
58+
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url')
59+
60+
# Clean branch names
4361
echo "$branches" > raw.txt
4462
echo "$branches" | tr '/":<>|*?\/\\' '-' > clean.txt
45-
paste -d ' ' raw.txt clean.txt | sed 's/ / -> /g'
63+
paste -d ' ' raw.txt clean.txt |
64+
while IFS=' ' read -r raw clean; do
65+
echo "| $raw | <$url$clean> |" >> summary.md
66+
done
67+
68+
{
69+
# Primary branch
70+
echo
71+
echo "Primary branch ($PRIMARY_BRANCH) is at:"
72+
echo "- <$url>"
73+
echo "- and <$url$PRIMARY_BRANCH>"
74+
} >> summary.md
75+
76+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
77+
{
78+
echo 'summary<<EOF'
79+
cat summary.md
80+
echo EOF
81+
} >> "$GITHUB_OUTPUT"
82+
83+
# Convert to a JSON list
4684
branches=$(echo "$branches" | jq -Rn '[inputs]')
47-
echo "branches=$(echo $branches)" >> $GITHUB_OUTPUT
85+
echo "branches=$(echo $branches)" >> "$GITHUB_OUTPUT"
86+
4887
4988
build-books:
5089
runs-on: ubuntu-latest
@@ -94,7 +133,6 @@ jobs:
94133
teachbooks build book/
95134
fi
96135
97-
98136
- name: Clean branch name of disallowed characters
99137
run: |
100138
echo "MATRIX_BRANCH_NAME_CLEAN=$(echo ${{ matrix.branch }} | tr '/":<>|*?\/\\' '-')" >> $GITHUB_ENV
@@ -109,6 +147,8 @@ jobs:
109147
# Run after build-books, even if it failed
110148
if: always()
111149
needs: build-books
150+
outputs:
151+
summary: ${{ steps.symlink-aliases.outputs.summary }}
112152
runs-on: ubuntu-latest
113153
permissions:
114154
pages: write
@@ -135,19 +175,35 @@ jobs:
135175
ls -a final/
136176
137177
- name: Symlink branch aliases
178+
id: symlink-aliases
138179
run: |
180+
{
181+
echo "### Aliases"
182+
# Summary table headers
183+
echo "| Alias :arrow_right: | Target :dart: | Link :link:"
184+
echo "| :--- | :--- | :--- |"
185+
} >> summary.md
186+
187+
url=$(gh api "repos/$GITHUB_REPOSITORY/pages" --jq '.html_url')
188+
139189
echo "$BRANCH_ALIASES" | tr ' ' '\n' | grep -E '\S' |
140190
while IFS=':' read -r key value; do
141191
# If the target branch is to be deployed, make symlink to it.
142192
if [ "$BRANCHES_TO_DEPLOY" == "*" ] || echo "$BRANCHES_TO_DEPLOY" | tr ' ' '\n' | grep "^$value$"; then
143193
# Clean branch names of special characters
144194
clean_key=$(echo "$key" | tr '/":<>|*?\/\\' '-')
145195
clean_value=$(echo "$value" | tr '/":<>|*?\/\\' '-')
146-
echo link "$clean_key" "->" "$clean_value"
196+
echo "| $clean_key | $clean_value | <$url$clean_key> |" >> summary.md
147197
ln -s "$clean_value" final/"$key"
148198
fi
149199
done
150200
201+
{
202+
echo 'summary<<EOF'
203+
cat summary.md
204+
echo EOF
205+
} >> "$GITHUB_OUTPUT"
206+
151207
- name: Upload final Pages artifact
152208
uses: actions/upload-pages-artifact@v3
153209
with:
@@ -157,6 +213,15 @@ jobs:
157213
id: deployment
158214
uses: actions/deploy-pages@v4
159215

216+
summarize:
217+
needs:
218+
- get-branches
219+
- deploy-books
220+
runs-on: ubuntu-latest
221+
steps:
222+
- run: |
223+
echo "${{ needs.get-branches.outputs.summary }}" >> $GITHUB_STEP_SUMMARY
224+
echo "${{ needs.deploy-books.outputs.summary }}" >> $GITHUB_STEP_SUMMARY
160225
161226
permissions:
162227
contents: read

0 commit comments

Comments
 (0)