Skip to content

Commit

Permalink
Add Flag to Enable/Disable Automatic Updates (#253)
Browse files Browse the repository at this point in the history
* Add version locking

* rename VERSION_LOCK to AUTO_UPDATES_ENABLED

* error for null versions

* rename

* fix typo for consistency

* fix version check

* break auto-update on first failure
  • Loading branch information
osterman authored Nov 7, 2019
1 parent 931c883 commit f8e6766
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 7 deletions.
34 changes: 29 additions & 5 deletions tasks/Makefile.package
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export PACKAGE_LICENSE ?= $(shell cat LICENSE 2>/dev/null)
export PACKAGE_HOMEPAGE_URL ?= https://github.com/$(VENDOR)/$(PACKAGE)
export PACKAGE_REPO_URL ?= https://github.com/$(VENDOR)/$(PACKAGE_REPO_NAME)

export AUTO_UPDATE_ENABLED ?= true

# Permit version to be overridden on the command line using PACKAGE_VERSION (e.g. FIGURINE_VERSION=0.3.0)
VERSION_ENV = $(shell basename $$(pwd) | tr '[:lower:]' '[:upper:]')_VERSION
ifneq ($($(VERSION_ENV)),)
Expand Down Expand Up @@ -88,7 +90,16 @@ DESCRIPTION:
@github-repo-metadata $(VENDOR) $(PACKAGE_REPO_NAME) "index" .description | tee DESCRIPTION

VERSION:
@github-repo-metadata $(VENDOR) $(PACKAGE_REPO_NAME) "releases/latest" .tag_name | sed 's/^v//' | tee VERSION
@version=$$(github-repo-metadata $(VENDOR) $(PACKAGE_REPO_NAME) "releases/latest" .tag_name | sed 's/^v//' | tr -d '\n'); \
if [ $$? -ne 0 ]; then \
exit 1; \
fi; \
if [ "$${version}" == "null" ] || [ "$${version}" == "" ]; then \
echo "ERROR: failed to obtain current version"; \
exit 1; \
else \
echo "$${version}" | tee VERSION; \
fi

LICENSE:
@github-repo-metadata $(VENDOR) $(PACKAGE_REPO_NAME) "license" .license.spdx_id | tr '[:lower:]' '[:upper:]' | tee LICENSE
Expand All @@ -111,19 +122,32 @@ init: VERSION LICENSE DESCRIPTION RELEASE

update: CURRENT_VERSION RELEASE

auto-update:
@if [ "$${AUTO_UPDATE_ENABLED}" == "true" ]; then \
$(MAKE) update; \
exit $?; \
else \
echo "Automatic updates disabled for $${PACKAGE_NAME}"; \
exit 0; \
fi

# The only way to tell if VERSION is up to date is to query the source via the internet
.PHONY: CURRENT_VERSION

# Update the VERSION file only if it would change, to avoid triggering unnecessary builds
CURRENT_VERSION:
@local_version=$$(cat VERSION || echo 0); \
current_version=$$(env PATH=$(PATH) github-repo-metadata $(VENDOR) $(PACKAGE_REPO_NAME) "releases/latest" .tag_name | sed 's/^v//'); \
if [ "$${local_version}" != "$${current_version}" ]; then \
echo Upgrading $(PACKAGE_NAME) from $${local_version} to $${current_version}; \
echo $${current_version} > VERSION; \
if [ $$? -ne 0 ]; then \
exit 1; \
elif [ "$${current_version}" == "null" ] || [ "$${current_version}" == "" ]; then \
echo "ERROR: failed to obtain current version (got: $${current_version})"; \
exit 1; \
elif [ "$${local_version}" != "$${current_version}" ]; then \
echo "Upgrading $(PACKAGE_NAME) from $${local_version} to $${current_version}"; \
echo "$${current_version}" > VERSION; \
fi


info:
@printf "%-20s %s\n" "Vendor:" "$(VENDOR)"
@printf "%-20s %s\n" "Package:" "$(PACKAGE_NAME)"
Expand Down
4 changes: 2 additions & 2 deletions vendor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ labeler:
done > ../.github/vendor.yml

## Update all packages
update:
find . -mindepth 1 -maxdepth 1 -type d | xargs -I{} make -C {} update
auto-update:
find . -mindepth 1 -maxdepth 1 -type d | xargs -I{} bash -c 'make -C {} auto-update || exit 255'

# Rebuild the APKINDEX if it's older than any of the *.apk files
$(APK_PACKAGE_INDEX): $(APK_PACKAGES)
Expand Down
3 changes: 3 additions & 0 deletions vendor/aws-okta/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export APK_BUILD_TEMPLATE ?= APKBUILD.github-binary
export APKBUILD_DEPENDS += libc6-compat
export PACKAGE_DESCRIPTION = aws-okta allows users to authenticate with AWS using Okta credentials

# Disable automatic updates until this is fixed: https://github.com/segmentio/aws-okta/issues/246
export AUTO_UPDATE_ENABLED = false

install:
$(call download_binary)

Expand Down
1 change: 1 addition & 0 deletions vendor/kubectl-1.13/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export INSTALL_DIR = /usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
export AUTO_UPDATE_ENABLED = false

install:
$(call download_binary)
Expand Down
1 change: 1 addition & 0 deletions vendor/kubectl-1.14/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export APK_BUILD_TEMPLATE = APKBUILD.github-binary
export APKBUILD_DEPENDS += dpkg
export APKBUILD_INSTALL_SCRIPTS = $(PACKAGE_NAME).post-install $(PACKAGE_NAME).post-deinstall
export INSTALL_DIR = /usr/share/${MASTER_PACKAGE_NAME}/${MAJOR_VERSION}/bin
export AUTO_UPDATE_ENABLED = false

install:
$(call download_binary)
Expand Down
2 changes: 2 additions & 0 deletions vendor/terraform-0.11/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Package details
export VENDOR ?= hashicorp
export APK_PACKAGE_NAME = terraform_0.11
export PACKAGE_REPO_NAME = terraform

include ../../tasks/Makefile.package
include ../../tasks/Makefile.apk

export APK_BUILD_TEMPLATE ?= APKBUILD.github-binary
export DOWNLOAD_URL ?= https://releases.hashicorp.com/terraform/$(PACKAGE_VERSION)/terraform_$(PACKAGE_VERSION)_$(OS)_$(ARCH).zip
export AUTO_UPDATE_ENABLED = false

install:
mkdir -p $(TMP)/$(PACKAGE_NAME)
Expand Down
2 changes: 2 additions & 0 deletions vendor/terraform-0.12/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Package details
export VENDOR ?= hashicorp
export APK_PACKAGE_NAME = terraform_0.12
export PACKAGE_REPO_NAME = terraform

include ../../tasks/Makefile.package
include ../../tasks/Makefile.apk

export APK_BUILD_TEMPLATE ?= APKBUILD.github-binary
export DOWNLOAD_URL ?= https://releases.hashicorp.com/terraform/$(PACKAGE_VERSION)/terraform_$(PACKAGE_VERSION)_$(OS)_$(ARCH).zip
export AUTO_UPDATE_ENABLED = false

install:
mkdir -p $(TMP)/$(PACKAGE_NAME)
Expand Down

0 comments on commit f8e6766

Please sign in to comment.