Skip to content

Commit

Permalink
Merge branch 'master' into changelogs-2.67
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestl committed Dec 4, 2024
2 parents b72a847 + e4a90bb commit 24a0034
Show file tree
Hide file tree
Showing 76 changed files with 2,561 additions and 1,453 deletions.
37 changes: 37 additions & 0 deletions .github/actions/combine-results/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Combine results
description: |
Determines a single result from one or more results. A single skipped or
failed will cause the action to fail. Details for each job will be output
as part of a results summary.
inputs:
needs-json:
description: Job outputs in JSON format
required: true
type: string

runs:
using: composite
steps:
- name: Summarise and combine results
shell: bash
run: |
needs_results=$(echo '${{ inputs.needs-json }}' | jq -r 'to_entries[] | "\(.key) \(.value.result)"')
echo "Summary:"
failed="false"
while IFS=" " read -r job result; do
if [[ "$result" != "success" ]]; then
failed="true"
echo "- ❌ Job \"$job\" returned result \"$result\""
else
echo "- ✅ Job \"$job\" returned result \"$result\""
fi
done <<< "$needs_results"
if [[ "$failed" == "false" ]]; then
echo "Overall result: success"
else
echo "Overall result: failure"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ runs:
run: |
sudo apt update
sudo apt build-dep -y "${{ inputs.snapd-src-dir }}"
rm -rf ./debian-deps
158 changes: 158 additions & 0 deletions .github/actions/resolve-go-channels/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Resolve Go snap channels
description: |
Compiles a list of Go snap channels with unique versions according to the
given optional input flags and specific channels. Looks up the snapd build
and snapd FIPS build Go channels from build-aux/snap/snapcraft.yaml. Assumes
risk stable if not specified.
inputs:
include-snapd-build-go-channel:
description: Flag instructing to include the channel of Go snap used to build Snapd snap
required: false
type: boolean
include-snapd-build-fips-go-channel:
description: Flag instructing to include the channel of Go snap used to build Snapd snap for FIPS
required: false
type: string
include-latest-go-channel:
description: Flag instructing to include the latest channel of Go snap
required: false
type: boolean
specific-go-channels:
description: Space separated list of required Go snap channels
required: false
type: string

outputs:
go-channels:
description: JSON list of Go snap channels
value: ${{ steps.resolve-go-channels.outputs.go-channels }}

runs:
using: composite
steps:
- name: Resolve Go snap channels
id: resolve-go-channels
shell: bash
run: |
# Get the Go snap version corresponding to a channel format <version>[/<risk>]
# - If optional risk is omitted, default stable will be assumed
# - Assumes both device and snap architecture amd64
go_version_from_channel() {
channel=$1
risk_default="stable"
arch_default="amd64"
# channel=<track>/<risk>
if [[ "$channel" =~ ^([0-9]+\.[0-9]+|[0-9]+\.[0-9]+-fips|latest)/(stable|candidate|beta|edge)$ ]]; then
track=${channel%%/*}
risk=${channel##*/}
# channel=<track>
elif [[ "$channel" =~ ^([0-9]+\.[0-9]+|[0-9]+\.[0-9]+-fips|latest)$ ]]; then
track=$channel
risk=$risk_default
# Not supported
else
echo "Cannot use Go channel \"$channel\""
return 1
fi
# Query params
device_arch="Snap-Device-Architecture: $arch_default"
channel_arch="$arch_default"
device_series="Snap-Device-Series: 16"
endpoint="https://api.snapcraft.io/v2/snaps/info/go"
# Query store
if ! result="$(curl -s --fail -H "$device_arch" -H "$device_series" -X GET "$endpoint")"; then
echo "Cannot use endpoint \"$endpoint\": $result"
return 1
else
version="$(jq -r ".\"channel-map\"[] \
| select ( .channel.track == \"$track\" and .channel.risk == \"$risk\" and .channel.architecture == \"$channel_arch\" ) \
| .version" <<< "$result")"
if [ -z "$version" ] || [ "$version" = "null" ]; then
echo "Cannot find version corresponding to: arch=$channel_arch, track=$track, risk=$track"
return 1
else
# Return the version
echo "$version"
fi
fi
}
go_channels=()
echo "Gathering required Go channels"
# Optional Go channel used to build Snapd snap
if [ "${{ inputs.include-snapd-build-go-channel }}" = "true" ]; then
echo "> Require Go channel used to build Snapd snap"
yaml="build-aux/snap/snapcraft.yaml"
if ! channel="$(yq '.parts.snapd.build-snaps[]' $yaml | grep "go/.*/.*")"; then
echo "Error: Cannot find valid Snapd build Go channel"
exit 1
fi
channel="$(yq '.parts.snapd.build-snaps[] | select(. == "go/*/*") | sub("^go/", "")' $yaml)"
echo "> Adding Go channel \"$channel\""
go_channels+=("$channel")
fi
# Optional Go channel used to build Snapd snap for FIPS
if [ "${{ inputs.include-snapd-build-fips-go-channel }}" = "true" ]; then
echo "> Require Go channel used to build Snapd snap for FIPS"
yaml="build-aux/snap/snapcraft.yaml"
if ! channel="$(yq '.parts.snapd.override-build' $yaml | grep "GO_TOOLCHAIN_FIPS_CHANNEL=\".*\"")"; then
echo "Error: Cannot find valid Snapd FIPS build Go channel"
exit 1
fi
channel="$(echo "$channel" | sed -n 's/^GO_TOOLCHAIN_FIPS_CHANNEL="\([^"]*\)"/\1/p')"
echo "> Adding Go channel \"$channel\""
go_channels+=("$channel")
fi
# Optional latest stable Go channel
if [ "${{ inputs.include-latest-go-channel }}" = "true" ]; then
echo "> Require latest stable Go channel"
channel="latest/stable"
echo "> Adding Go channel \"$channel\""
go_channels+=("$channel")
fi
# Optional specific Go channel(s)
if [ -n "${{ inputs.specific-go-channels }}" ]; then
echo "> Require specific Go channel(s)"
for channel in ${{ inputs.specific-go-channels }}; do
echo "> Adding Go channel \"$channel\""
go_channels+=("$channel")
done
fi

declare -A go_versions
go_channels_with_unique_version=()
echo "Dropping Go channels that duplicates Go versions"

# Iterate all the required channels and create list of
# channels with unique versions.
for channel in "${go_channels[@]}"; do
if ! output="$(go_version_from_channel "$channel")"; then
echo "Error: $output"
else
if [[ -v go_versions["$output"] ]]; then
echo "> Dropping channel \"$channel\": same Go version as channel \"${go_versions[$output]}\""
else
echo "> Keeping channel \"$channel\" with unique Go version \"$output\""
go_versions["$output"]="$channel"
go_channels_with_unique_version+=("$channel")
fi
fi
done

# Convert to single line JSON array and remove duplicates
go_channels_output="[]"
if [[ ${#go_channels_with_unique_version[@]} -gt 0 ]]; then
go_channels_output="$(printf '%s\n' "${go_channels_with_unique_version[@]}" | jq -R . | jq -s -c .)"
fi
echo "Unique Go channels: $go_channels_output"

# Output the single line JSON array
echo "go-channels=$go_channels_output" >> "$GITHUB_OUTPUT"
19 changes: 11 additions & 8 deletions .github/workflows/spread-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ jobs:
if [ -f "$FAILED_TESTS_FILE" ]; then
echo "Failed tests file found"
FAILED_TESTS="$(cat $FAILED_TESTS_FILE)"
if [ -n "$FAILED_TESTS" ]; then
echo "Failed tests to run: $FAILED_TESTS"
echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV
fi
echo "Failed tests to run: $FAILED_TESTS"
echo "FAILED_TESTS=$FAILED_TESTS" >> $GITHUB_ENV
fi
- name: Setup run tests variable
Expand Down Expand Up @@ -228,7 +226,12 @@ jobs:
# propagated; and we use a subshell as this option could trigger
# undesired changes elsewhere
echo "Running command: $SPREAD $RUN_TESTS"
(set -o pipefail; $SPREAD -no-debug-output -logs spread-logs $RUN_TESTS | PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-filter $FILTER_PARAMS | tee spread.log)
(
set -o pipefail
$SPREAD -no-debug-output -logs spread-logs $RUN_TESTS | \
./tests/lib/external/snapd-testing-tools/utils/log-filter $FILTER_PARAMS | \
tee spread.log
)
- name: Upload spread logs
if: always()
Expand All @@ -252,7 +255,7 @@ jobs:
if [ -e spread.log ]; then
echo "Running spread log analyzer"
ACTIONS_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json --cut 1 >/dev/null
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json --cut 1 >/dev/null
while IFS= read -r line; do
if [ ! -z "$line" ]; then
echo "Adding failed test line to filtered log"
Expand All @@ -268,15 +271,15 @@ jobs:
run: |
if [ -f spread.log ]; then
echo "Running spread log parser"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json
./tests/lib/external/snapd-testing-tools/utils/log-parser spread.log --output spread-results.json
# Add openstack backend definition to spread.yaml
if [ "${{ inputs.backend }}" = openstack ]; then
./tests/lib/spread/add-backend tests/lib/spread/backend.openstack.yaml spread.yaml
fi
echo "Running spread log analyzer"
PYTHONDONTWRITEBYTECODE=1 ./tests/lib/external/snapd-testing-tools/utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE"
./tests/lib/external/snapd-testing-tools/utils/log-analyzer list-reexecute-tasks "$RUN_TESTS" spread-results.json > "$FAILED_TESTS_FILE"
echo "List of failed tests saved"
cat "$FAILED_TESTS_FILE"
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/static-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
static-checks:
runs-on: ${{ inputs.runs-on }}
env:
GOPATH: ${{ github.workspace }}
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
Expand All @@ -30,21 +29,17 @@ jobs:
with:
# needed for git commit history
fetch-depth: 0
# NOTE: checkout the code in a fixed location, even for forks, as this
# is relevant for go's import system.
path: ./src/github.com/snapcore/snapd

# Fetch base ref, needed for golangci-lint
- name: Fetching base ref ${{ github.base_ref }}
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd
git fetch origin ${{ github.base_ref }}:${{ github.base_ref }}
- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./src/github.com/snapcore/snapd/.github/workflows/actions/download-install-debian-deps
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}/src/github.com/snapcore/snapd"
snapd-src-dir: "${{ github.workspace }}"

# golang latest ensures things work on the edge
- name: Install the go snap
Expand All @@ -58,7 +53,7 @@ jobs:
- name: Get C vendoring
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/c-vendor && ./vendor.sh
cd c-vendor && ./vendor.sh
- name: Install golangci-lint snap
run: |
Expand All @@ -68,7 +63,7 @@ jobs:
id: changed-files
uses: tj-actions/changed-files@v41.0.0
with:
path: ./src/github.com/snapcore/snapd
path: ./

- name: Save changes files
run: |
Expand All @@ -78,7 +73,6 @@ jobs:
- name: Run static checks
run: |
cd ${{ github.workspace }}/src/github.com/snapcore/snapd || exit 1
# run gofmt checks only with the latest stable Go
if [ "${{ matrix.gochannel }}" != "latest/stable" ]; then
export SKIP_GOFMT=1
Expand Down Expand Up @@ -113,7 +107,7 @@ jobs:
- name: Check C source code formatting
run: |
set -x
cd ${{ github.workspace }}/src/github.com/snapcore/snapd/cmd/
cd cmd/
./autogen.sh
# apply formatting
PATH=${{ github.workspace }}/indent-bin/opt/indent/bin:$PATH make fmt
Expand Down
Loading

0 comments on commit 24a0034

Please sign in to comment.