Skip to content

Build and Upload Release #1

Build and Upload Release

Build and Upload Release #1

Workflow file for this run

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: 1
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