WIP: test snap in same job that generates it #76
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | ||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
# to execute once a day (more info see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule ) | ||
schedule: | ||
- cron: "0 0 * * *" | ||
env: | ||
SNAPCRAFT_STORE_CREDENTIALS: ${{secrets.SNAPCRAFT_LOGIN}} | ||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: "ubuntu:22.04" | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Install required dependencies | ||
run: | | ||
apt update | ||
apt install --yes sudo | ||
sudo apt install --yes --no-install-recommends git | ||
# workaround for https://github.com/actions/runner/issues/2033 | ||
git config --global --add safe.directory '*' | ||
- name: Setup .NET | ||
run: | | ||
# We need to install `ca-certificates`, otherwise we get these errors in the CI: | ||
# Unable to load the service index for source https://api.nuget.org/v3/index.json. | ||
# The SSL connection could not be established, see inner exception. | ||
# The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot | ||
apt install --yes --no-install-recommends ca-certificates | ||
apt install --yes --no-install-recommends dotnet7 | ||
- name: Build | ||
run: dotnet build | ||
build_snap: | ||
needs: build | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Install snap tools | ||
run: | | ||
sudo apt update | ||
sudo apt install -y snapd | ||
snap version | ||
sudo snap install --classic snapcraft | ||
# workaround for GithubActionsCI+snapcraft, see https://forum.snapcraft.io/t/permissions-problem-using-snapcraft-in-azure-pipelines/13258/14 | ||
sudo chown root:root / | ||
snapcraft --version | ||
# use multipass provider as lxd doesn't work for some reason | ||
sudo snap install multipass | ||
sudo snap set snapcraft provider=multipass | ||
- name: Build | ||
run: dotnet build --configuration Release | ||
- name: Generate snap package | ||
run: sudo snapcraft --destructive-mode --verbosity=verbose || sudo bash -c 'cat /root/.local/state/snapcraft/log/*.log' | ||
- uses: actions/upload-artifact@v3 | ||
name: Upload snap package as artifact | ||
with: | ||
name: snap | ||
path: ./*.snap | ||
- name: Install snap | ||
run: | | ||
sudo snap install --devmode --dangerous *.snap | ||
- name: Test snap | ||
run: dotnet-fsharp-helloworld | ||
integration_tests: | ||
strategy: | ||
matrix: | ||
# macos-13 is x64 and macos-14 is arm64 | ||
os: [ubuntu-22.04, macos-13, macos-14, windows-latest] | ||
needs: build | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Run Tests | ||
run: dotnet test | ||
conventions: | ||
needs: | ||
- integration_tests | ||
- build_snap | ||
runs-on: ubuntu-22.04 | ||
container: | ||
image: "ubuntu:22.04" | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Install required dependencies | ||
run: | | ||
apt update | ||
apt install --yes sudo | ||
sudo apt install --yes --no-install-recommends git | ||
# workaround for https://github.com/actions/runner/issues/2033 | ||
git config --global --add safe.directory '*' | ||
- name: Setup .NET | ||
run: | | ||
# We need to install `ca-certificates`, otherwise we get these errors in the CI: | ||
# Unable to load the service index for source https://api.nuget.org/v3/index.json. | ||
# The SSL connection could not be established, see inner exception. | ||
# The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot | ||
apt install --yes --no-install-recommends ca-certificates | ||
apt install --yes --no-install-recommends dotnet6 | ||
- name: fantomas | ||
run: | | ||
dotnet new tool-manifest | ||
dotnet tool install fantomas --version 6.2.3 | ||
dotnet fantomas . | ||
git diff --exit-code | ||
publish_snap: | ||
needs: | ||
- run_snap | ||
- integration_tests | ||
- conventions | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
name: Download artifact | ||
with: | ||
name: snap | ||
- name: Unzip | ||
run: | | ||
zip -r snap.zip . | ||
- name: Install snapcraft | ||
run: | | ||
sudo snap install --classic snapcraft | ||
snapcraft --version | ||
- name: Upload to SnapStore | ||
#FIXME: add github.event_name == 'push' condition to the 'if:' condition below? | ||
if: startsWith(github.ref, 'refs/tags/') | ||
run: | | ||
# no need to 'snapcraft login' first, see https://forum.snapcraft.io/t/snapcraft-authentication-options/30473/21 | ||
snapcraft upload *.snap --release=beta | ||