Skip to content

Commit

Permalink
chores: Fix flaky CI (#1627)
Browse files Browse the repository at this point in the history
* Improve curl error handling

* Add curl-dev

* Allow passing GITHUB_TOKEN to install script

* Pass GITHUB_TOKEN to e2e and install script workflows
  • Loading branch information
wata727 authored Dec 25, 2022
1 parent 75aa36e commit 5e9f2c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ jobs:
cache: true
- name: Run e2e
run: make e2e
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .github/workflows/install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: |
./install_linux.sh
tflint -v
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install specific version
env:
TFLINT_VERSION: v0.15.0
Expand All @@ -40,6 +42,7 @@ jobs:
"$TFLINT_INSTALL_PATH/tflint" -v
env:
TFLINT_INSTALL_PATH: ${{ github.workspace }}/install-path
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
container:
runs-on: ubuntu-latest
Expand All @@ -51,7 +54,7 @@ jobs:
uses: actions/checkout@v3
- name: Install dependencies
run: |
apk add bash curl unzip
apk add bash curl curl-dev unzip
- name: Install latest version
run: |
./install_linux.sh
Expand Down
23 changes: 12 additions & 11 deletions install_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ echo "os=$os"
echo -e "\n\n===================================================="

get_latest_release() {
curl --silent "https://api.github.com/repos/terraform-linters/tflint/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
headers=()
if [ -n "${GITHUB_TOKEN}" ]; then
headers=(-H "Authorization: Bearer ${GITHUB_TOKEN}")
fi
curl --fail -sS "${headers[@]}" "https://api.github.com/repos/terraform-linters/tflint/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}

download_path=$(mktemp -d -t tflint.XXXXXXXXXX)
Expand All @@ -46,20 +50,17 @@ download_executable="${download_path}/tflint"

if [ -z "${TFLINT_VERSION}" ] || [ "${TFLINT_VERSION}" == "latest" ]; then
echo "Looking up the latest version ..."
if [ -n "${GITHUB_TOKEN}" ]; then
echo "Requesting with GITHUB_TOKEN ..."
fi
version=$(get_latest_release)
else
version=${TFLINT_VERSION}
fi

echo "Downloading TFLint $version"
curl --fail --silent -L -o "${download_zip}" "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Failed to download tflint_${os}.zip"
exit $retVal
else
echo "Downloaded successfully"
fi
curl --fail -sS -L -o "${download_zip}" "https://github.com/terraform-linters/tflint/releases/download/${version}/tflint_${os}.zip"
echo "Downloaded successfully"

echo -e "\n\n===================================================="
echo "Unpacking ${download_zip} ..."
Expand Down

0 comments on commit 5e9f2c1

Please sign in to comment.