Repository navigation
146 lines (123 loc) · 4.42 KB
/
Copy pathci.yml
File metadata and controls
146 lines (123 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v23
- name: Run ShellCheck
run: nix develop --command shellcheck --shell=bash devcontainer-sh
- name: Run actionlint
run: nix develop --command actionlint
- name: Build the Nix package
run: nix build
test:
strategy:
fail-fast: false
matrix:
# macOS runs the macOS system bash, 3.2, through /bin/bash first on PATH.
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v23
- name: Run Tests
run: nix develop --command bats tests/
- name: Run Tests with the system bash
if: runner.os == 'macOS'
run: |
mkdir -p "$RUNNER_TEMP/bash32"
ln -s /bin/bash "$RUNNER_TEMP/bash32/bash"
# PATH is changed inside the dev shell, so bats and the rest of its
# tools are still found; only `bash` now resolves to the system one.
# shellcheck disable=SC2016 # the inner sh expands these, on purpose
nix develop --command sh -c '
PATH="$1:$PATH"
bash --version | head -1
bats tests/
' _ "$RUNNER_TEMP/bash32"
# The action, used the way a workflow would use it, against a real container.
action:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Use the action
uses: ./
- name: Start the dev container
run: devcontainer-sh up --workspace-folder tests/fixtures/workspace
- name: Run a command in it
run: |
out="$(devcontainer-sh exec --workspace-folder tests/fixtures/workspace -- sh -c 'echo ok && id -un')"
echo "$out"
test "$(printf '%s\n' "$out" | head -1)" = ok
- name: The exit status comes through
run: |
if devcontainer-sh exec --workspace-folder tests/fixtures/workspace -- false; then
echo "expected a failure" >&2
exit 1
fi
- name: Remove the dev container
if: always()
run: devcontainer-sh down --workspace-folder tests/fixtures/workspace
- name: Start a compose dev container
run: devcontainer-sh up --workspace-folder tests/fixtures/compose
- name: Down removes every service and the network, not only the workspace
run: |
project=compose_devcontainer
services() { docker ps -aq --filter "label=com.docker.compose.project=$project" | wc -l | tr -d ' '; }
test "$(services)" = 2
devcontainer-sh down --workspace-folder tests/fixtures/compose
test "$(services)" = 0
test -z "$(docker network ls -q --filter "label=com.docker.compose.project=$project")"
release:
needs: [lint, test, action]
if: github.event_name == 'push'
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
permissions:
contents: write
issues: write
pull-requests: write
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Create Release PR
id: release
uses: googleapis/release-please-action@v5
with:
manifest-file: .github/config/release-please-manifest.json
config-file: .github/config/release-please-config.json
target-branch: main
# Callers pin the major version, e.g. @v1, so it follows every release.
- name: Move the major version tag
if: steps.release.outputs.release_created
env:
TAG: ${{ steps.release.outputs.tag_name }}
MAJOR: v${{ steps.release.outputs.major }}
run: |
git fetch --tags --quiet
git tag --force "$MAJOR" "$TAG"
git push --force origin "$MAJOR"