Update Github Actions checkout and upload. (#444) #83
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and publish to Docker | |
# Push seems to be triggered for both refs/heads/... and refs/tags/... | |
# So there is no need to trigger on release: { types: [published] } | |
on: | |
push: | |
jobs: | |
job: | |
name: Build and Publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the changes | |
uses: actions/checkout@v4 | |
- name: main | |
run: | | |
make test | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
unset VERSION | |
set -eux | |
if [[ "${GITHUB_REF:?}" == "refs/heads/master" ]]; then | |
# Master branch -- builds latest image | |
export VERSION="latest" | |
elif [[ "${GITHUB_REF:?}" =~ ^refs/heads/v([0-9]+\.[0-9]+(-.*)?)$ ]]; then | |
# Any vNNN.NNN branch -- builds "test-NNN.NNN" image | |
# Also allows vNNN.NNN-XXX -- where XXX could be anything (builds test-NNN.NNN-XXX) | |
export VERSION="test-${BASH_REMATCH[1]}" | |
elif [[ "${GITHUB_REF:?}" =~ ^refs/tags/indoorequal-v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
# Any vNNN.NNN.NNN tag (not branch!) -- builds "NNN.NNN.NNN" and "NNN.NNN" images | |
# This means that the two-part version image will always point to latest patch. | |
export VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]} \ | |
${BASH_REMATCH[1]}.${BASH_REMATCH[2]}" | |
echo "Current content of openmaptiles/__init__.py:" | |
cat openmaptiles/__init__.py | |
echo "Updating version in openmaptiles/__init__.py to ${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}" | |
sed -i -e 's/^__version__ = '"'"'[0-9]\+[.][0-9]\+[.][0-9]\+'"'"'/__version__ = '"'${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}'"'/g' openmaptiles/__init__.py | |
echo "New content of openmaptiles/__init__.py:" | |
cat openmaptiles/__init__.py | |
else | |
echo "Unrecognized ref ${GITHUB_REF}, no docker images are built or uploaded" | |
exit 0 | |
fi | |
echo "Building and publishing tags $VERSION" | |
function push_docker { | |
for ver in $VERSION; do | |
docker push ghcr.io/indoorequal/$1:$ver | |
done | |
} | |
df -h . | |
make build-docker | |
push_docker openmaptiles-tools | |
# Github has a very low disk limit, get rid of some data | |
df -h . | |
sudo docker system prune --all --force | |
df -h . | |
# TODO: fix unavailable image error inside the make target | |
NO_REFRESH=1 make build-postgis | |
push_docker postgis | |
df -h . |