Skip to content

Commit 2072f6c

Browse files
Improve Docker Builds and Add Testing Flag (#7)
1 parent 1a8f8a0 commit 2072f6c

File tree

3 files changed

+63
-42
lines changed

3 files changed

+63
-42
lines changed

.github/workflows/build-and-test.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ on:
2525
required: false
2626
type: boolean
2727
default: true
28+
test:
29+
description: 'A flag indicating if the Swift package contains tests'
30+
required: false
31+
type: boolean
32+
default: true
2833
testdocc:
2934
description: 'A flag indicating if the DocC documentation building should be tested'
3035
required: false
@@ -58,7 +63,7 @@ jobs:
5863
working-directory: ${{ inputs.path }}
5964
steps:
6065
- uses: actions/checkout@v2
61-
- uses: maxim-lobanov/setup-xcode@v1.4.0
66+
- uses: maxim-lobanov/setup-xcode@v1
6267
with:
6368
xcode-version: latest
6469
- name: Check Environment
@@ -81,16 +86,16 @@ jobs:
8186
if: matrix.configuration == 'release'
8287
run: swift build -c release
8388
- name: Release Build & Test
84-
if: matrix.configuration == 'release_testing'
89+
if: matrix.configuration == 'release_testing' && inputs.test
8590
run: swift test -c release -Xswiftc -enable-testing -Xswiftc -DRELEASE_TESTING
8691
- name: Debug Build & Test
87-
if: matrix.configuration == 'debug'
92+
if: matrix.configuration == 'debug' && inputs.test
8893
run: swift test -c debug --enable-code-coverage -Xswiftc -DCOVERAGE
8994
- name: Convert coverage report
90-
if: matrix.configuration == 'debug'
95+
if: matrix.configuration == 'debug' && inputs.test
9196
run: xcrun llvm-cov export -format="lcov" .build/debug/${{ inputs.packagename }}PackageTests.xctest/Contents/MacOS/${{ inputs.packagename }}PackageTests -instr-profile .build/debug/codecov/default.profdata > coverage.lcov
9297
- name: Upload coverage to Codecov
93-
if: matrix.configuration == 'debug'
98+
if: matrix.configuration == 'debug' && inputs.test
9499
uses: codecov/codecov-action@v2
95100
linux:
96101
name: Linux ${{ matrix.linux }} ${{ matrix.configuration }}
@@ -140,10 +145,10 @@ jobs:
140145
if: matrix.configuration == 'release'
141146
run: swift build -c release
142147
- name: Release Build & Test
143-
if: matrix.configuration == 'release_testing'
148+
if: matrix.configuration == 'release_testing' && inputs.test
144149
run: swift test -c release -Xswiftc -enable-testing -Xswiftc -DRELEASE_TESTING
145150
- name: Debug Build & Test
146-
if: matrix.configuration == 'debug'
151+
if: matrix.configuration == 'debug' && inputs.test
147152
run: swift test -c debug
148153
generate-docs:
149154
name: Generate Docs
@@ -154,7 +159,7 @@ jobs:
154159
working-directory: ${{ inputs.path }}
155160
steps:
156161
- uses: actions/checkout@v2
157-
- uses: maxim-lobanov/setup-xcode@v1.4.0
162+
- uses: maxim-lobanov/setup-xcode@v1
158163
with:
159164
xcode-version: latest
160165
- name: Check Environment

.github/workflows/docker-build-and-push.yml

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,9 @@ on:
2727
default: '.'
2828

2929
jobs:
30-
docker:
31-
name: Docker Build and Push Image ${{ matrix.architecture }}
32-
runs-on: ubuntu-latest
33-
strategy:
34-
matrix:
35-
architecture: [arm64, amd64]
30+
dockerARM64:
31+
name: Docker Build and Push Image ARM64
32+
runs-on: ARM64
3633
defaults:
3734
run:
3835
working-directory: ${{ inputs.working-directory }}
@@ -44,48 +41,54 @@ jobs:
4441
uses: WyriHaximus/github-action-get-previous-tag@v1
4542
with:
4643
fallback: latest
47-
- name: Set up QEMU
48-
uses: docker/setup-qemu-action@v1
44+
- name: Log in to the container registry
45+
uses: docker/login-action@v1
4946
with:
50-
platforms: linux/${{ matrix.architecture }}
51-
- name: Set up docker buildx
52-
uses: docker/setup-buildx-action@v1
47+
registry: ghcr.io
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Build and push docker image
51+
id: buildandpush
52+
uses: docker/build-push-action@v2
5353
with:
54-
install: true
55-
- name: Docker meta
56-
id: meta
57-
uses: docker/metadata-action@v3
54+
context: .
55+
file: ${{ inputs.docker-file }}
56+
build-args: |
57+
baseimage=swiftarm/swift:5.5.1-ubuntu-focal
58+
push: true
59+
tags: ghcr.io/${{ inputs.image-name }}:latest-arm64,ghcr.io/${{ inputs.image-name }}:${{ steps.latesttag.outputs.tag }}-arm64
60+
dockerAMD64:
61+
name: Docker Build and Push Image AMD64
62+
runs-on: ubuntu-latest
63+
defaults:
64+
run:
65+
working-directory: ${{ inputs.working-directory }}
66+
steps:
67+
- name: Checkout repository
68+
uses: actions/checkout@v2
69+
- name: Get latest tag
70+
id: latesttag
71+
uses: WyriHaximus/github-action-get-previous-tag@v1
5872
with:
59-
images: ${{ inputs.image-name }}
73+
fallback: latest
6074
- name: Log in to the container registry
6175
uses: docker/login-action@v1
6276
with:
6377
registry: ghcr.io
6478
username: ${{ github.actor }}
6579
password: ${{ secrets.GITHUB_TOKEN }}
66-
- name: Determine Base Image
67-
uses: haya14busa/action-cond@v1
68-
id: baseimage
69-
with:
70-
cond: ${{ matrix.architecture == 'arm64' }}
71-
if_true: 'swiftarm/swift:5.5.1-ubuntu-focal'
72-
if_false: 'swift:focal'
7380
- name: Build and push docker image
7481
id: buildandpush
7582
uses: docker/build-push-action@v2
7683
with:
7784
context: .
7885
file: ${{ inputs.docker-file }}
7986
build-args: |
80-
baseimage=${{ steps.baseimage.outputs.value }}
87+
baseimage=swift:focal
8188
push: true
82-
platforms: linux/${{ matrix.architecture }}
83-
tags: ghcr.io/${{ inputs.image-name }}:latest-${{ matrix.architecture }},ghcr.io/${{ inputs.image-name }}:${{ steps.latesttag.outputs.tag }}-${{ matrix.architecture }}
84-
labels: ${{ steps.meta.outputs.labels }}
85-
- name: Image digest
86-
run: echo ${{ steps.buildandpush.outputs.digest }}
89+
tags: ghcr.io/${{ inputs.image-name }}:latest-amd64,ghcr.io/${{ inputs.image-name }}:${{ steps.latesttag.outputs.tag }}-amd64
8790
dockermanifest:
88-
needs: [docker]
91+
needs: [dockerARM64, dockerAMD64]
8992
name: Create Multi-CPU Architecture Image
9093
runs-on: ubuntu-latest
9194
steps:

.github/workflows/docs.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: macos-11
2323
steps:
2424
- uses: actions/checkout@v2
25-
- uses: maxim-lobanov/setup-xcode@v1.4.0
25+
- uses: maxim-lobanov/setup-xcode@v1
2626
with:
2727
xcode-version: latest
2828
- uses: actions/cache@v2
@@ -34,7 +34,20 @@ jobs:
3434
xcodebuild -version
3535
swift --version
3636
echo "inputs.packagename: ${{ inputs.packagename }}"
37-
- uses: DoccZz/docc2ghpages@v1
37+
- name: Generate Documentation
38+
run: |
39+
rm -rf ~/.xcodebuild
40+
mkdir ~/.xcodebuild
41+
xcodebuild docbuild -scheme ${{ inputs.packagename }} -destination platform=macOS -derivedDataPath ~/.xcodebuild
42+
cp -r $(find ~/.xcodebuild -type d -name '${{ inputs.packagename }}.doccarchive') ./${{ inputs.packagename }}.doccarchive
43+
echo "The DocC archive can be found at ./${{ inputs.packagename }}.doccarchive"
44+
- name: Genereate static HTML page
45+
run: |
46+
git clone https://github.com/DoccZz/docc2html.git
47+
cd docc2html
48+
swift run docc2html ../${{ inputs.packagename }}.doccarchive ../docs
49+
- uses: peaceiris/actions-gh-pages@v3
3850
with:
39-
scheme: ${{ inputs.packagename }}
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
github_token: ${{ github.token }}
52+
publish_dir: ./docs
53+
force_orphan: true

0 commit comments

Comments
 (0)