Skip to content
Snippets Groups Projects
Unverified Commit 761289c0 authored by Andrew Newdigate's avatar Andrew Newdigate
Browse files

feat: asdf validation check

parent cf5cbcb5
No related branches found
No related tags found
No related merge requests found
# DO NOT MANUALLY EDIT; Run ./scripts/update-asdf-version-variables to update this
variables:
GL_ASDF_GOLANG_VERSION: 1.17.6
GL_ASDF_SHELLCHECK_VERSION: 0.7.0
GL_ASDF_SHFMT_VERSION: 3.0.2
Loading
Loading
@@ -2,11 +2,11 @@ stages:
- validate
- release
 
# variables:
# GL_ASDF_GOLANGCI_LINT_VERSION: 1.41.1
include:
- local: .gitlab-ci-asdf-versions.yml
# disabled as there are no golang files to run
# - local: golangci-lint.yml
- local: editorconfig-check.yml
- local: semantic-release.yml
- local: asdf-tool-versions.yml
# For first-time installation, you'll need to install all plugins:
# Use the script: ./scripts/install-asdf-plugins.sh
# NOTE: please add new plugins to ./scripts/install-asdf-plugins.sh when adding items here
golang 1.17.6
shellcheck 0.7.0
shfmt 3.0.2
Loading
Loading
@@ -155,3 +155,27 @@ include:
- project: 'gitlab-com/gl-infra/common-ci-tasks'
file: goreleaser.yml
```
### [`asdf-tool-versions`](./asdf-tool-versions.yml)
Checks that the `.tool-versions` file is synced with .gitlab-ci-asdf-versions.yml, that all the plugins are declared in `./scripts/install-asdf-plugins.sh` and that ASDF is generally working.
* Default Stages: `validate`
Setup process:
1. Ensure that the file [`scripts/install-asdf-plugins.sh`](https://gitlab.com/gitlab-com/runbooks/-/blob/master/scripts/install-asdf-plugins.sh) exists in the repository. Tailor for the `asdf` configuration of the project.
1. Ensure that the files [`scripts/update-asdf-version-variables.sh`](https://gitlab.com/gitlab-com/runbooks/-/blob/master/scripts/update-asdf-version-variables.sh) exists in the repository.
1. Add the include to your `.gitlab-ci.yml` file:
```yaml
include:
- local: .gitlab-ci-asdf-versions.yml
# Checks that the `.tool-versions` file is synced with .gitlab-ci-asdf-versions.yml,
# that all the plugins are declared in `./scripts/install-asdf-plugins.sh`
# and that ASDF is generally working
- project: 'gitlab-com/gl-infra/common-ci-tasks'
ref: v0.0.0 # Look this up https://gitlab.com/gitlab-com/gl-infra/common-ci-tasks/-/releases
file: asdf-tool-versions.yml
```
validate_asdf_tool_versions:
stage: validate
image: "ubuntu:21.04"
needs: []
variables:
ASDF_DIR: /asdf
script:
- apt-get update && apt-get install -y jq curl git bash build-essential libssl-dev zlib1g-dev
- if [[ -n "${GL_ASDF_LEGACY_VERSIONS_FILE}" ]]; then echo "legacy_version_file = yes" >> ~/.asdfrc; fi
- git clone https://github.com/asdf-vm/asdf.git "${ASDF_DIR}"
- source "${ASDF_DIR}/asdf.sh"
- ./scripts/install-asdf-plugins.sh
- ./scripts/update-asdf-version-variables.sh
- git diff --exit-code
rules:
# This script can be quite slow (mostly due to the ruby install)
# so we only run it when there have been changes
- if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- changes:
- scripts/install-asdf-plugins.sh
- scripts/update-asdf-version-variables.sh
- go.mod
- .tool-versions
- .ruby-version
- .gitlab-ci-asdf-versions.yml
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
plugin_list=$(asdf plugin list || echo "")
install_plugin() {
plugin=$1
if ! echo "$plugin_list" | grep -q "${plugin}" >/dev/null; then
echo "# Installing plugin" "$@"
asdf plugin add "$@" || {
echo "Failed to perform plugin installation: " "$@"
return 1
}
fi
echo "# Installing ${plugin} version"
asdf install "${plugin}" || {
echo "Failed to perform version installation: ${plugin}"
return 1
}
}
check_global_golang_install() {
(
pushd /
asdf current golang
popd
) >/dev/null 2>/dev/null
}
# Install golang first as some of the other plugins require it
install_plugin golang
if [[ -z "${CI:-}" ]]; then
# The go-jsonnet plugin requires a global golang version to be configured
# and will otherwise fail to install
#
# This check is not neccessary in CI
GOLANG_VERSION=$(asdf current golang | awk '{print $2}')
if ! check_global_golang_install; then
cat <<-EOF
---------------------------------------------------------------------------------------
The go-jsonnet plugin requires a global golang version to be configured.$
Suggestion: run this command to set this up: 'asdf global golang ${GOLANG_VERSION}'
Then rerun this command.
Note: you can undo this change after running this command by editing ~/.tool-versions
---------------------------------------------------------------------------------------
EOF
exit 1
fi
fi
install_plugin shellcheck
install_plugin shfmt
#!/usr/bin/env bash
# See the README.md for details of how this script works
set -euo pipefail
IFS=$'\n\t'
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
asdf_current() {
asdf current 2>&1 || {
echo "# asdf current failed"
exit 1
}
}
generate() {
asdf_current |
grep "${ROOT_DIR}/" |
awk '
BEGIN {
print "# DO NOT MANUALLY EDIT; Run ./scripts/update-asdf-version-variables to update this";
print "variables:"
}
{
gsub("-", "_", $1);
print " GL_ASDF_" toupper($1) "_VERSION: " $2
}
'
}
generate >"${ROOT_DIR}/.gitlab-ci-asdf-versions.yml"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment