innernet-debian/.github/workflows/main.yml

247 lines
8.7 KiB
YAML
Raw Normal View History

name: Update Repository
# Controls when the workflow will run
on:
#push:
# If the configuration has changed, this ensures we apply updates.
#branches: [ main ]
schedule:
# Upstream releases around once per month, so twice a week should be fine.
- cron: '23 14 * * mon,thu'
workflow_dispatch:
jobs:
check-upstream:
name: Check for a new releases upstream
runs-on: ubuntu-latest
outputs:
innernet_release: ${{ steps.check-latest-release.outputs.innernet_release }}
2023-05-01 07:25:15 +00:00
innernet_version: ${{ steps.check-latest-release.outputs.innernet_version }}
tarball_url: ${{ steps.check-latest-release.outputs.tarball_url }}
new_release_exists: ${{ steps.check-repo-release.outputs.new_release_exists }}
2023-05-01 07:25:15 +00:00
steps:
- name: Install Distro Dependencies
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes jq liblzma-dev reprepro
2023-05-01 07:25:15 +00:00
- name: Set Ubuntu Release Name
id: set-ubuntu-release-name
run: |
echo "ubuntu_release=$(lsb_release --short --codename)" >>"$GITHUB_OUTPUT"
- name: Check Latest Release
id: check-latest-release
run: |
wget -O- \
-H'Accept: application/json' \
2023-02-17 14:15:02 +00:00
"https://api.github.com/repos/tonarino/innernet/releases/latest" \
| jq -r '(.name + " " + .tarball_url)' \
| (
read release tarball_url
echo "innernet_release=$release" >>"$GITHUB_OUTPUT"
2023-05-01 07:25:15 +00:00
echo "innernet_version=${release#v}" >>"$GITHUB_OUTPUT"
echo "tarball_url=$tarball_url" >>"$GITHUB_OUTPUT"
2023-03-20 16:59:36 +00:00
echo "Latest release: $release"
)
- name: Checkout
2023-05-12 13:21:21 +00:00
uses: actions/checkout@v3
with:
# See https://github.com/marketplace/actions/github-push
persist-credentials: false
fetch-depth: 0
- name: Check Repo Release
id: check-repo-release
run: |
new_release_exists=
for ver_codename in ubuntu-22.04/jammy ubuntu-20.04/focal; do
ver=${ver_codename%/*}
codename=${ver_codename##*/}
# Note the leading v to match the Git tag.
indexed=v$(reprepro -b debian --list-format '${version}\n' listmatched "$codename" innernet)
upstream="${{ steps.check-latest-release.outputs.innernet_release }}-0ubuntu0~$codename"
echo "Repo release in $codename: $indexed"
if [ "x$indexed" != "x$upstream" ]; then
new_release_exists="${new_release_exists:+$new_release_exists,}\"$ver\""
fi
done
echo "new_release_exists=[$new_release_exists]" >>"$GITHUB_OUTPUT"
2023-05-01 07:25:15 +00:00
2023-03-20 16:54:26 +00:00
- name: Show Output
id: show-output
run: |
echo "## Job Outputs" >>"$GITHUB_STEP_SUMMARY"
echo "* \`innernet_release=${{ steps.check-latest-release.outputs.innernet_release }}\`" >>"$GITHUB_STEP_SUMMARY"
2023-05-01 07:25:15 +00:00
echo "* \`innernet_version=${{ steps.check-latest-release.outputs.innernet_version }}\`" >>"$GITHUB_STEP_SUMMARY"
echo "* \`new_release_exists=${{ steps.check-repo-release.outputs.new_release_exists }}\`" >>"$GITHUB_STEP_SUMMARY"
build-deb:
name: Build DEB Packages
needs: [check-upstream]
if: "fromJson(needs.check-upstream.outputs.new_release_exists)[0] != null"
2023-05-01 07:25:15 +00:00
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ${{ fromJson(needs.check-upstream.outputs.new_release_exists) }}
steps:
- name: Install Distro Dependencies
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes dpkg-dev liblzma-dev
- name: Translate Codename
id: translate-codename
run: |
case "${{ matrix.os }}" in
2023-05-12 14:28:29 +00:00
ubuntu-22.04) codename=jammy ;;
ubuntu-20.04) codename=focal ;;
*)
echo "Unknown OS: ${{ matrix.os }}" >&2
exit 1
;;
esac
echo "codename=$codename" >>"$GITHUB_OUTPUT"
- name: Download Latest Release
id: download-release
run: |
wget -O- "${{ needs.check-upstream.outputs.tarball_url }}" | tar xz
mv tonarino-innernet-*/* .
rm -fr tonarino-innernet-*
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install cargo-deb
run: |
type -p cargo-deb || cargo install cargo-deb
- name: Set Up Rust Cache
uses: Swatinem/rust-cache@v1
2023-05-01 07:25:15 +00:00
with:
key: ${{ matrix.os }}
- name: Build Client DEB
uses: actions-rs/cargo@v1
with:
command: deb
args: -p client --deb-version=${{ needs.check-upstream.outputs.innernet_version }}-0ubuntu0~${{ steps.translate-codename.outputs.codename }}
2023-05-01 07:25:15 +00:00
- name: Build Server DEB
uses: actions-rs/cargo@v1
with:
command: deb
args: -p server --deb-version=${{ needs.check-upstream.outputs.innernet_version }}-0ubuntu0~${{ steps.translate-codename.outputs.codename }}
- name: Upload DEBs
2023-05-12 13:21:21 +00:00
uses: actions/upload-artifact@v3
with:
name: deb-${{ matrix.os }}
path: target/debian/*.deb
2023-05-01 07:25:15 +00:00
- name: Show Output
id: show-output
run: |
echo "## Job Outputs" >>"$GITHUB_STEP_SUMMARY"
echo "* \`codename=${{ steps.translate-codename.outputs.codename }}\`" >>"$GITHUB_STEP_SUMMARY"
release:
needs: [check-upstream, build-deb]
2023-05-01 07:25:15 +00:00
# Avoid push conflicts.
concurrency: update_repository
2023-05-15 15:19:44 +00:00
if: "matrix.os[0] != null"
2023-05-01 07:25:15 +00:00
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ${{ fromJson(needs.check-upstream.outputs.new_release_exists) }}
steps:
- name: Install Distro Dependencies
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes git gpg reprepro
- name: Set Up GPG Keys
2021-09-11 10:32:50 +00:00
run: |
2021-09-11 11:16:10 +00:00
mkdir -p -m 0700 "$HOME/.gnupg"
2021-09-11 11:19:43 +00:00
echo 'pinentry-mode loopback' >>"$HOME/.gnupg/gpg.conf"
echo 'allow-loopback-pinentry' >>"$HOME/.gnupg/gpg-agent.conf"
echo 'allow-preset-passphrase' >>"$HOME/.gnupg/gpg-agent.conf"
2021-09-11 11:06:31 +00:00
gpgconf --reload gpg-agent
2021-09-11 10:32:50 +00:00
echo "${{ secrets.GPG_SIGNING_KEY }}" | gpg --quiet --batch --yes --import
2021-09-11 11:21:31 +00:00
echo '${{ secrets.GPG_SIGNING_PASSPHRASE }}' | /usr/lib/gnupg/gpg-preset-passphrase --preset 57F0E65446A301CC19914FD61167922350A2D8B2
- name: Translate Codename
id: translate-codename
run: |
case "${{ matrix.os }}" in
2023-05-12 14:28:29 +00:00
ubuntu-22.04) codename=jammy ;;
ubuntu-20.04) codename=focal ;;
*)
echo "Unknown OS: ${{ matrix.os }}" >&2
exit 1
;;
esac
echo "codename=$codename" >>"$GITHUB_OUTPUT"
- name: Checkout
2023-05-12 13:21:21 +00:00
uses: actions/checkout@v3
with:
# See https://github.com/marketplace/actions/github-push
persist-credentials: false
fetch-depth: 0
- name: Download DEBs
2023-05-12 13:21:21 +00:00
uses: actions/download-artifact@v3
with:
name: deb-${{ matrix.os }}
path: ./artifacts
2023-05-01 07:25:15 +00:00
- name: Import DEBs
run: |
cd artifacts
for name in *.deb; do
reprepro --export=silent-never -b ../debian includedeb "${{ steps.translate-codename.outputs.codename }}" "$name"
done
2023-05-01 07:25:15 +00:00
- name: Update Repository
run: |
has_changes() {
git status --porcelain "$@" | grep -q .
}
if has_changes debian/pool; then
reprepro -b debian export "${{ steps.translate-codename.outputs.codename }}"
fi
if has_changes debian/{db,dists,pool}; then
git add debian/{db,dists,pool}
git \
-c 'user.email=41898282+github-actions[bot]@users.noreply.github.com' \
-c 'user.name=github-actions[bot]' \
commit -m "Included release tonarino/innernet@${{ needs.check-upstream.outputs.innernet_release }} in ${{ steps.translate-codename.outputs.codename }}."
else
echo 'No updates to commit.'
fi
- name: Push changes
2023-05-12 13:11:21 +00:00
uses: ad-m/github-push-action@master
2023-05-01 07:25:15 +00:00
if: github.ref_name == 'main'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
2021-09-11 09:51:17 +00:00
branch: ${{ github.ref }}
2023-05-12 13:11:21 +00:00
# GitHub shows an inconsistent delay with pulling right after pushing. Since we push
# for multiple distributions, we have to make sure the next checkout doesn't conflict
# with the current.
- name: Delay 30 seconds for pushed changes to be visible
run: sleep 30s
shell: bash