Skip to content

Commit

Permalink
Workflow scripts improvements (#225)
Browse files Browse the repository at this point in the history
* Send Discord notifications when new commits are added to the stable
  and testing branches and result in a successful CI build.
* Factor out the logic for synchronizing with the remote server to a
  `sync-repository` action.
* Factor out the logic for fetching build dependencies to a
  `setup` action.
  • Loading branch information
matteodelabre committed Jan 15, 2021
1 parent c7f3198 commit cb362f5
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 60 deletions.
51 changes: 51 additions & 0 deletions .github/actions/discord-send/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Send a Discord message
description: Send a message to a Discord channel
inputs:
channel:
description: Identifier of the channel to send the message to
required: true
token:
description: API access token
required: true
title:
description: Title of the message to send
required: true
link:
description: URL to link the message title to
required: true
color:
description: Color to annotate the message with
required: true
message:
description: Content of the message to send
required: true
runs:
using: composite
steps:
- name: Post to the Discord REST API
shell: bash
env:
MSG_TITLE: ${{ inputs.title }}
MSG_LINK: ${{ inputs.link }}
MSG_COLOR: ${{ inputs.color }}
MSG_VALUE: ${{ inputs.message }}
run: |
payload="$(jq --null-input --compact-output --monochrome-output \
--arg title "$MSG_TITLE" \
--arg link "$MSG_LINK" \
--arg color "$MSG_COLOR" \
--arg message "$MSG_VALUE" \
'{
username: "Toltec",
avatar_url: "https://avatars0.githubusercontent.com/u/71158884",
embeds: [{
title: $title,
url: $link,
color: $color,
description: $message,
}]
}')"
curl --silent --show-error --fail \
--header "Content-Type: application/json" \
--data "$payload" \
'https://discord.com/api/webhooks/${{ inputs.channel }}/${{ inputs.token }}'
37 changes: 37 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Setup Toltec dependencies
runs:
using: "composite"
steps:
- name: Install Ubuntu packages
shell: bash
run: |
sudo apt-get update -yq
sudo apt-get install -yq bsdtar tree
- name: Install shfmt and Shellcheck
shell: bash
run: |
install_dir=/usr/local/bin
# Install shfmt
shfmt_version=v3.2.1
shfmt_checksum=43439b996942b53dfafa9b6ff084f394555d049c98fb7ec37978f7668b43e1be
sudo curl --location --silent --fail --tlsv1.2 --proto '=https' \
--output "$install_dir"/shfmt \
https://github.com/mvdan/sh/releases/download/"$shfmt_version"/shfmt_"$shfmt_version"_linux_amd64
sha256sum -c <(echo "$shfmt_checksum $install_dir/shfmt") > /dev/null 2>&1
sudo chmod a+x "$install_dir"/shfmt
# Install Shellcheck (Ubuntu’s version is too old)
shellcheck_version=v0.7.1
shellcheck_checksum=64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8
shellcheck_arname=shellcheck.tar.xz
curl --location --silent --fail --tlsv1.2 --proto '=https' \
--output "$shellcheck_arname" \
https://github.com/koalaman/shellcheck/releases/download/"$shellcheck_version"/shellcheck-"$shellcheck_version".linux.x86_64.tar.xz
sha256sum -c <(echo "$shellcheck_checksum $shellcheck_arname") > /dev/null 2>&1
tar -xf "$shellcheck_arname" --strip-components=1 \
shellcheck-"$shellcheck_version"/shellcheck
rm "$shellcheck_arname"
chmod a+x shellcheck
sudo chown root:root shellcheck
sudo mv shellcheck "$install_dir"
31 changes: 31 additions & 0 deletions .github/actions/sync-repository/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Sync with remote repository
description: Synchronize packages with a remote repository
inputs:
local-path:
description: Path to the directory containing the packages to push
required: true
ssh-key:
description: Private SSH key to access the remote repository
required: true
ssh-known-hosts:
description: Public SSH key of the remote repository
required: true
remote-path:
description: Path to the remote directory to place the packages in
required: true
runs:
using: composite
steps:
- name: rsync packages and index
shell: bash
run: |
mkdir -p private
chmod 700 private
echo '${{ inputs.ssh-key }}' > private/id_rsa
echo '${{ inputs.ssh-known-hosts }}' > private/known_hosts
chmod 600 private/*
rsync --archive --verbose --compress --delete \
-e "ssh -i private/id_rsa -o UserKnownHostsFile=private/known_hosts" \
'${{ inputs.local-path }}' \
'${{ inputs.remote-path }}'
rm -r private
4 changes: 2 additions & 2 deletions .github/workflows/pr-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
steps:
- name: Check labels
run: |
[[ "${{ github.base_ref }}" != stable ]] \
|| [[ "${{ contains(github.event.pull_request.labels.*.name, 'merge') }}" == true ]]
[[ '${{ github.base_ref }}' != stable ]] \
|| [[ '${{ contains(github.event.pull_request.labels.*.name, 'merge') }}' == true ]]
35 changes: 5 additions & 30 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,8 @@ jobs:
steps:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Install missing tools
run: |
install_dir=/usr/local/bin
# Install shfmt
shfmt_version=v3.1.2
shfmt_checksum=c5794c1ac081f0028d60317454fe388068ab5af7740a83e393515170a7157dce
sudo curl --location --silent --fail --tlsv1.2 --proto '=https' \
--output "$install_dir"/shfmt \
https://github.com/mvdan/sh/releases/download/"$shfmt_version"/shfmt_"$shfmt_version"_linux_amd64
sha256sum -c <(echo "$shfmt_checksum $install_dir/shfmt") > /dev/null 2>&1
sudo chmod a+x "$install_dir"/shfmt
# Install Shellcheck (Ubuntu’s version is too old)
shellcheck_version=v0.7.1
shellcheck_checksum=64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8
shellcheck_arname=shellcheck.tar.xz
curl --location --silent --fail --tlsv1.2 --proto '=https' \
--output "$shellcheck_arname" \
https://github.com/koalaman/shellcheck/releases/download/"$shellcheck_version"/shellcheck-"$shellcheck_version".linux.x86_64.tar.xz
sha256sum -c <(echo "$shellcheck_checksum $shellcheck_arname") > /dev/null 2>&1
tar -xf "$shellcheck_arname" --strip-components=1 \
shellcheck-"$shellcheck_version"/shellcheck
rm "$shellcheck_arname"
chmod a+x shellcheck
sudo chown root:root shellcheck
sudo mv shellcheck "$install_dir"
- name: Setup Toltec environment
uses: ./.github/actions/setup
- name: Check formatting
run: make format
- name: Check for erroneous constructs
Expand All @@ -46,10 +21,10 @@ jobs:
steps:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Install missing tools
run: sudo apt-get install bsdtar tree
- name: Setup Toltec environment
uses: ./.github/actions/setup
- name: Build packages
run: remote_repo="https://toltec-dev.org/${{ github.base_ref }}" make repo-new
run: remote_repo='https://toltec-dev.org/${{ github.base_ref }}' make repo-new
- name: Save the build output
uses: actions/upload-artifact@v2
with:
Expand Down
34 changes: 19 additions & 15 deletions .github/workflows/stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,25 @@ jobs:
steps:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Install missing tools
run: |
sudo apt-get install bsdtar tree
- name: Setup Toltec dependencies
uses: ./.github/actions/setup
- name: Build packages
run: |
remote_repo="https://toltec-dev.org/stable" make repo
- name: Transfer packages and index
run: |
mkdir -p private
chmod 700 private
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private/id_rsa
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > private/known_hosts
chmod 600 private/*
rsync --archive --verbose --compress --delete \
-e "ssh -i private/id_rsa -o UserKnownHostsFile=private/known_hosts" \
build/repo/ "${{ secrets.REMOTE }}":/srv/toltec/stable
scp -i private/id_rsa -o UserKnownHostsFile=private/known_hosts \
scripts/bootstrap/bootstrap "${{ secrets.REMOTE }}":/srv/toltec
- name: Sync packages with the remote repository
uses: ./.github/actions/sync-repository
with:
local-path: build/repo/
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
remote-path: ${{ secrets.REMOTE }}:/srv/toltec/stable
- name: Send notification to Discord
continue-on-error: true
uses: ./.github/actions/discord-send
with:
channel: ${{ secrets.DISCORD_STABLE_CHANNEL_ID }}
token: ${{ secrets.DISCORD_STABLE_CHANNEL_TOKEN }}
title: New Toltec stable update available
link: https://toltec-dev.org/stable
color: 0x2ea043
message: ${{ github.event.head_commit.message }}
32 changes: 19 additions & 13 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ jobs:
steps:
- name: Checkout the Git repository
uses: actions/checkout@v2
- name: Install missing tools
run: |
sudo apt-get install bsdtar tree
- name: Setup Toltec dependencies
uses: ./.github/actions/setup
- name: Build packages
run: |
remote_repo="https://toltec-dev.org/testing" make repo
- name: Transfer packages and index
run: |
mkdir -p private
chmod 700 private
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private/id_rsa
echo "${{ secrets.SSH_KNOWN_HOSTS }}" > private/known_hosts
chmod 600 private/*
rsync --archive --verbose --compress --delete \
-e "ssh -i private/id_rsa -o UserKnownHostsFile=private/known_hosts" \
build/repo/ "${{ secrets.REMOTE }}":/srv/toltec/testing
- name: Sync packages with the remote repository
uses: ./.github/actions/sync-repository
with:
local-path: build/repo/
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
ssh-known-hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
remote-path: ${{ secrets.REMOTE }}:/srv/toltec/testing
- name: Send notification to Discord
continue-on-error: true
uses: ./.github/actions/discord-send
with:
channel: ${{ secrets.DISCORD_TESTING_CHANNEL_ID }}
token: ${{ secrets.DISCORD_TESTING_CHANNEL_TOKEN }}
title: New Toltec testing update available
link: https://toltec-dev.org/testing
color: 0xe3b341
message: ${{ github.event.head_commit.message }}

0 comments on commit cb362f5

Please sign in to comment.