Skip to content

Commit eacafc9

Browse files
committed
provide GitHub Action
1 parent b80b245 commit eacafc9

File tree

4 files changed

+94
-16
lines changed

4 files changed

+94
-16
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
fail-fast: false
4646
matrix:
4747
os:
48+
- ubuntu-latest
4849
- ubuntu-22.04
4950
- ubuntu-20.04
5051
- windows-latest
@@ -53,18 +54,24 @@ jobs:
5354
- name: Git Checkout
5455
uses: actions/checkout@v3 #https://github.com/actions/checkout
5556

57+
- name: "Linux: Configure APT"
58+
uses: ./
59+
with:
60+
repo-name: ${{ github.repository }}
61+
repo-branch: ${{ github.ref_name }}
62+
5663
- name: Run shellcheck
5764
run: bash tests/run-shellcheck.sh
5865

5966
- name: Install bashcov
60-
if: ${{ runner.os == 'Linux' }}
67+
if: ${{ runner.os == 'Linux' && !env.ACT }}
6168
run: sudo gem install bashcov simplecov-console
6269

6370
- name: Run tests
6471
timeout-minutes: 5
6572
run: |
6673
set -eu
67-
if [[ "${{ runner.os }}" == "Linux" ]]; then
74+
if [[ "${{ runner.os }}" == "Linux" && "${{ env.ACT }}" != "true" ]]; then
6875
bashcov --skip-uncovered tests/run-tests.sh
6976
else
7077
bash tests/run-tests.sh

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
**Feedback and high-quality pull requests are highly welcome!**
1010

1111
1. [What is it?](#what-is-it)
12-
1. [Installation](#installation)
13-
1. [Usage](#usage)
12+
1. [Usage as GitHub Action](#github_action)
13+
1. [Usage on the commandline](#cli)
14+
1. [Installation](#installation)
1415
1. [`current` command](#current-command)
1516
1. [`find` command](#find-command)
1617
1. [`set` command](#set-command)
@@ -24,10 +25,31 @@
2425
on [Debian](https://www.debian.org/), [Ubuntu](https://ubuntu.com/), [Pop!_OS](https://pop.system76.com/) systems.
2526

2627
It was born out of the ongoing stability [issues](https://github.com/actions/runner-images/issues?q=is%3Aissue+azure.archive.ubuntu.com) with the `azure.archive.ubuntu.com` Ubuntu
27-
mirror pre-configured in Github Actions runners.
28+
mirror pre-configured in GitHub Actions runners.
29+
30+
31+
## <a name="github_action"></a>Usage as GitHub Action
32+
33+
```yaml
34+
name: Build
35+
on: [ push, pull_request ]
36+
jobs:
37+
build:
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Configure Fast APT Mirror
41+
uses: vegardit/fast-apt-mirror.sh@v1
42+
with: # the following parameters are listed with their action default values and are optional
43+
healthchecks: 20 # Number of mirrors from the mirrors list to check for availability and up-to-dateness
44+
speedtests: 10 # Maximum number of healthy mirrors to test for speed
45+
parallel: 2 # Number of parallel speed tests
46+
sample-size: 1024 # Number of kilobytes to download during the speed from each mirror
47+
sample-time: 3 # Maximum number of seconds within the sample download from a mirror must finish
48+
```
2849
50+
## <a name="cli"></a>Usage on the command line
2951
30-
## <a name="installation"></a>Installation
52+
### <a name="installation"></a>Installation
3153
3254
For example:
3355
```bash
@@ -37,13 +59,9 @@ $ sudo apt-get install -y bash curl apt-transport-https ca-certificates
3759
# install fast-apt-mirror.sh under /usr/local/bin/ to make it automatically available via $PATH
3860
$ sudo curl https://raw.githubusercontent.com/vegardit/fast-apt-mirror.sh/v1/fast-apt-mirror.sh -o /usr/local/bin/fast-apt-mirror.sh
3961
$ sudo chmod 755 /usr/local/bin/fast-apt-mirror.sh
40-
```
41-
42-
43-
## <a name="usage"></a>Usage
4462

45-
Available sub commands:
46-
```yml
63+
# show the help
64+
$ fast-apt-mirror.sh --help
4765
fast-apt-mirror.sh COMMAND
4866

4967
Available commands:
@@ -78,11 +96,11 @@ Usage:
7896
fast-apt-mirror.sh find [OPTION]...
7997
8098
Options:
81-
--apply - Replaces the current APT mirror in /etc/apt/sources.list with a fast mirror and runs 'sudo apt-get update'
99+
--apply - Replaces the current APT mirror in /etc/apt/(sources.list|sources.list.d/system.sources) with a fast mirror and runs 'sudo apt-get update'
82100
--exclude-current - If specified, don't include the current APT mirror in the speed tests.
83-
-p, --parallel N - Number of parallel speed tests. May result in incorrect results because of competing connections but finds a suitable mirror faster.
84-
--healthchecks N - Number of mirrors from the Ubuntu/Debian mirror lists to check for availability and up-to-dateness - default is 20
101+
--healthchecks N - Number of mirrors from the mirrors list to check for availability and up-to-dateness - default is 20
85102
--speedtests N - Maximum number of healthy mirrors to test for speed - default is 5
103+
-p, --parallel N - Number of parallel speed tests. May result in incorrect results because of competing connections but finds a suitable mirror faster.
86104
--sample-size KB - Number of kilobytes to download during the speed from each mirror - default is 200KB
87105
--sample-time SECS - Maximum number of seconds within the sample download from a mirror must finish - default is 3
88106
-v, --verbose - More output. Specify multiple times to increase verbosity.

action.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com) and contributors
2+
# SPDX-FileContributor: Sebastian Thomschke, Vegard IT GmbH
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
6+
name: Configure fast APT mirror
7+
description: Configures a fast APT mirror in Ubuntu runners, e.g. in case azure.archive.ubuntu.com is slow or unreachable.
8+
author: Vegard IT GmbH (https://vegardit.com)
9+
branding:
10+
color: blue
11+
icon: settings
12+
13+
inputs:
14+
healthchecks: { default: "20", description: "Number of mirrors from the mirrors list to check for availability and up-to-dateness." }
15+
speedtests: { default: "10", description: "Maximum number of healthy mirrors to test for speed." }
16+
parallel: { default: "2", description: "Number of parallel speed tests. May result in incorrect results because of competing connections but finds a suitable mirror faster." }
17+
sample-size: { default: "1024", description: "Number of kilobytes to download during the speed from each mirror." }
18+
sample-time: { default: "3", description: "Maximum number of seconds within the sample download from a mirror must finish." }
19+
20+
repo-name: { default: "vegardit/fast-apt-mirror.sh", description: "Repository containing the fast-apt-mirror.sh script" }
21+
repo-branch: { default: "v1", description: "Version (i.e. github branch) of the fast-apt-mirror.sh script to use" }
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: "Linux: Configure fast APT mirror"
27+
if: runner.os == 'Linux'
28+
shell: bash
29+
run: |
30+
echo "::group::Linux: Configure fast APT mirror"
31+
set -euo pipefail
32+
33+
echo 'APT::Acquire::Retries "3";' | sudo tee /etc/apt/apt.conf.d/80-acquire-retries
34+
35+
if [[ "${{ env.ACT }}" != "true" ]]; then
36+
# Workaround to avoid sporadic connectivity issues "Could not connect to azure.archive.ubuntu.com:80"
37+
# see https://github.com/actions/runner-images/issues/675
38+
# see https://github.com/actions/runner-images/issues/704
39+
curl -sSfL https://raw.githubusercontent.com/${{ inputs.repo-name }}/${{ inputs.repo-branch }}/fast-apt-mirror.sh -o $HOME/fast-apt-mirror.sh
40+
bash $HOME/fast-apt-mirror.sh find --apply -v \
41+
--healthchecks ${{ inputs.healthchecks }} \
42+
--speedtests ${{ inputs.speedtests }} \
43+
--parallel ${{ inputs.parallel }} \
44+
--sample-size ${{ inputs.sample-size }} \
45+
--sample-time ${{ inputs.sample-time }}
46+
fi
47+
48+
# refresh pkg cache if it does not exist or is older than 60min.
49+
# avoid potential 404 see https://github.com/actions/runner-images/issues/592
50+
if [[ ! -e /var/lib/apt/lists/partial ]] || [[ $(( $(date +%s) - $(sudo date +%s -r /var/lib/apt/lists/partial) )) -gt 3600 ]]; then
51+
sudo apt-get update
52+
fi
53+
echo "::endgroup::"

fast-apt-mirror.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ function find_fast_mirror() {
196196
echo "Options:"
197197
echo " --apply - Replaces the current APT mirror in /etc/apt/(sources.list|sources.list.d/system.sources) with a fast mirror and runs 'sudo apt-get update'"
198198
echo " --exclude-current - If specified, don't include the current APT mirror in the speed tests."
199-
echo " -p, --parallel N - Number of parallel speed tests. May result in incorrect results because of competing connections but finds a suitable mirror faster."
200199
echo " --healthchecks N - Number of mirrors from the mirrors list to check for availability and up-to-dateness - default is 20"
201200
echo " --speedtests N - Maximum number of healthy mirrors to test for speed - default is 5"
201+
echo " -p, --parallel N - Number of parallel speed tests. May result in incorrect results because of competing connections but finds a suitable mirror faster."
202202
echo " --sample-size KB - Number of kilobytes to download during the speed from each mirror - default is 200KB"
203203
echo " --sample-time SECS - Maximum number of seconds within the sample download from a mirror must finish - default is 3"
204204
echo " -v, --verbose - More output. Specify multiple times to increase verbosity."

0 commit comments

Comments
 (0)