-
Notifications
You must be signed in to change notification settings - Fork 86
139 lines (113 loc) · 5.7 KB
/
main.yml
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
135
136
137
138
139
name: Build and Upload Release
on:
push:
tags:
- 'v**'
# Allow running manually from the actions tab
workflow_dispatch:
env:
# See: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio
IMAGE_NAME: 5etools
# Used to force a clean (i.e., non-incremental) Docker build
DO_CLEAN_BUILD: 0
concurrency:
group: "release"
cancel-in-progress: true
jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Generate Release Notes
run: bash ./.github/generate-release-notes.sh ${{ github.ref_name }} | tee RELEASE_NOTES.md
- name: Archive Release
run: |
zip -r 5etools-${{ github.ref_name }}.zip . -x '*.git*' '*node_modules*' '*.github*'
- name: Upload Release
run: |
gh release create "${{github.ref_name}}" --title "${{github.ref_name}}" --notes-file RELEASE_NOTES.md 5etools-${{ github.ref_name }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
# See: https://stackoverflow.com/a/58178121
- name: Set Env
run: |
IMAGE_VERSION=${{ github.ref_name }}
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && IMAGE_VERSION=$(echo $IMAGE_VERSION | sed -e 's/^v//')
echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV
echo "IMAGE_ID_SRC=$(echo ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME-src | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
echo "IMAGE_ID_IMG=$(echo ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME-img | tr '[A-Z]' '[a-z]')" >> $GITHUB_ENV
- name: Set Deployed Flag
run: |
bash ./.github/set-deployed-flag.sh ${{ github.ref_name }}
# Remove entries from the `.gitignore` so the gh-pages action can correctly add+commit them to the pages branch
- name: Build Service Worker
run: |
node --version
npm --version
npm i
npm run build:sw:prod
sed -i 's/sw.js//g' .gitignore
sed -i 's/sw-injector.js//g' .gitignore
- name: Build SEO Pages
env:
VET_SEO_IS_DEV_MODE: true
VET_BASE_SITE_URL: "https://${{ github.repository_owner }}.github.io/"
VET_SEO_IS_SKIP_UA_ETC: true
run: |
npm run build:seo -- ${{ github.ref_name }}
# region See: https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#upgrading-a-workflow-that-accesses-ghcrio
- name: Build Image
run: |
if [[ "${{ github.ref }}" == "refs/tags/"* ]]
then
VERSION_ARRAY=( ${IMAGE_VERSION//./ } )
MAJOR=${VERSION_ARRAY[0]}
MINOR=${VERSION_ARRAY[1]}
POINT=${VERSION_ARRAY[2]}
# Create a clean docker image every 4 minor version.
if [[ $(echo "$MINOR % 4" | bc) == 0 && $POINT == 0 ]]
then
DO_CLEAN_BUILD=1
fi
fi
if [[ $DO_CLEAN_BUILD == 1 ]]
then
# Build a clean image
echo "Version is ${{ github.ref_name }}, doing a clean docker build"
docker build -t $IMAGE_NAME-src .
else
# Build an incremental image...
echo "Version is ${{ github.ref_name }}, doing an incremental docker build"
# Pull the old images
docker pull $IMAGE_ID_SRC:latest
docker pull $IMAGE_ID_IMG:latest
# Save the current CMD from the image
SAVE_CMD=$(docker inspect --format='{{json .Config.Cmd}}' $IMAGE_ID_SRC:latest)
# Convert .dockerignore to .rsync-filter
bash ./.github/create-rsync-filter.sh
# Copy img files to host
docker run --rm -v "$(pwd)":/tmp/5et-new $IMAGE_ID_IMG:latest rsync -rlcv --filter='dir-merge /tmp/5et-new/.rsync-filter' /var/www/localhost/htdocs/img /tmp/5et-new/
docker rmi $(docker images -q $IMAGE_ID_IMG:*)
# Run up the previous containers, and rsync the current new of files into it
CONTAINER_ID=$(docker run -d -v "$(pwd)":/tmp/5et-new $IMAGE_ID_SRC:latest rsync -rlcvF --delete-excluded /tmp/5et-new/ /var/www/localhost/htdocs/)
docker logs -f $CONTAINER_ID
# Commit the changes
docker commit -c "CMD $SAVE_CMD" $CONTAINER_ID $IMAGE_NAME-src
fi
- name: Log In to Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push Image
run: |
echo IMAGE_ID_SRC=$IMAGE_ID_SRC
echo IMAGE_VERSION=$IMAGE_VERSION
docker tag $IMAGE_NAME-src $IMAGE_ID_SRC:$IMAGE_VERSION
# Always tag latest when pushing a tag, as we don't expect to ever merge old tags
[[ "${{ github.ref }}" == "refs/tags/"* ]] && docker tag $IMAGE_NAME-src $IMAGE_ID_SRC:latest
docker push $IMAGE_ID_SRC:$IMAGE_VERSION
docker push $IMAGE_ID_SRC:latest
# endregion