-
-
Notifications
You must be signed in to change notification settings - Fork 27
174 lines (168 loc) · 6.64 KB
/
action-e2e.yaml
File metadata and controls
174 lines (168 loc) · 6.64 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# End-to-end tests for the Publish to BCR custom GitHub action
name: action-e2e
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
# Cancel previous actions from the same PR or branch except 'main' branch.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
cancel-in-progress: ${{ github.ref_name != 'main' }}
jobs:
# Each job is an e2e test. Unfortunately a full workflow cannot be added as
# required status check on branch protection rules, so each test must be added
# as a required check: https://github.com/orgs/community/discussions/12395.
test-happy-path:
# Create a new module entry and test the content
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: this
- name: Setup test fixture
run: this/e2e/action/setup-test-fixture.sh versioned versioned-1.0.0
- name: Create registry
run: |
mkdir -p bazel-central-registry/modules
cd bazel-central-registry
git init
- name: Create entry
id: create_entry
uses: ./this
with:
tag: v1.0.0
module-version: 1.0.0
github-repository: foobar/versioned
templates-dir: this/e2e/fixtures/versioned/.bcr
local-registry: bazel-central-registry
- name: Test entry content
run: this/e2e/action/test-happy-path-content.sh
- name: Test outputs
run: |
set -o errexit -o nounset -o pipefail -o xtrace
EXPECTED="versioned"
ACTUAL="${{ steps.create_entry.outputs.module-names }}"
if [[ "${ACTUAL}" != "${EXPECTED}" ]]; then
echo "Expected output module-names to be '${EXPECTED}' but it was '${ACTUAL}'"
exit 1
fi
EXPECTED="versioned@1.0.0"
ACTUAL="${{ steps.create_entry.outputs.short-description }}"
if [[ "${ACTUAL}" != "${EXPECTED}" ]]; then
echo "Expected output short-description to be '${EXPECTED}' but it was '${ACTUAL}'"
exit 1
fi
test-github-repository-default:
# Test that the `github-repository` input defaults to ${{ github.repository }}
# indirectly by checking the resulting subtituted source.json file in the entry.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: this
- name: Setup test fixture
run: this/e2e/action/setup-test-fixture.sh versioned publish-to-bcr-1.0.0
- name: Create registry
run: |
mkdir -p bazel-central-registry/modules
cd bazel-central-registry
git init
- name: Create entry
uses: ./this
with:
tag: v1.0.0
module-version: 1.0.0
templates-dir: this/e2e/fixtures/versioned/.bcr
local-registry: bazel-central-registry
- name: Test repository substitution
run: this/e2e/action/test-github-repository-default-substitution.sh
test-attestations:
# Test that attestations are created when `attest` is set to true
runs-on: ubuntu-latest
# Attestations cannot be used from a fork https://github.com/actions/attest-build-provenance/issues/99
if: ${{ github.repository == 'bazel-contrib/publish-to-bcr' }}
permissions:
id-token: write
attestations: write
steps:
- uses: actions/checkout@v2
with:
path: this
- name: Setup test fixture
run: this/e2e/action/setup-test-fixture.sh versioned versioned-1.0.0
- name: Create registry
run: |
mkdir -p bazel-central-registry/modules
cd bazel-central-registry
git init
- name: Create entry
uses: ./this
with:
attest: true
attestations-dest: attestations
tag: v1.0.0
module-version: 1.0.0
github-repository: foobar/versioned
templates-dir: this/e2e/fixtures/versioned/.bcr
local-registry: bazel-central-registry
- name: Test attestations exist
run: |
set -o errexit -o nounset -o pipefail -o xtrace
[ -f attestations/MODULE.bazel.intoto.jsonl ]
[ -f attestations/source.json.intoto.jsonl ]
test-multi-module:
# Tests a multi-module publish
runs-on: ubuntu-latest
# Attestations cannot be used from a fork https://github.com/actions/attest-build-provenance/issues/99
if: ${{ github.repository == 'bazel-contrib/publish-to-bcr' }}
permissions:
id-token: write
attestations: write
steps:
- uses: actions/checkout@v2
with:
path: this
- name: Setup test fixture
run: this/e2e/action/setup-test-fixture.sh multi-module multi-module-1.0.0
- name: Create registry
run: |
mkdir -p bazel-central-registry/modules
cd bazel-central-registry
git init
- name: Create entry
id: create_entry
uses: ./this
with:
attest: true
attestations-dest: attestations
tag: v1.0.0
module-version: 1.0.0
github-repository: testorg/multi-module
templates-dir: this/e2e/fixtures/multi-module/.bcr
local-registry: bazel-central-registry
# Test that attestation files are given a prefixed name when multiple modules are published
- name: Test attestations exist
run: |-
set -o errexit -o nounset -o pipefail -o xtrace
[ -f attestations/module.MODULE.bazel.intoto.jsonl ]
[ -f attestations/module.source.json.intoto.jsonl ]
[ -f attestations/submodule.MODULE.bazel.intoto.jsonl ]
[ -f attestations/submodule.source.json.intoto.jsonl ]
- name: Test outputs
run: |-
set -o errexit -o nounset -o pipefail -o xtrace
EXPECTED="module,submodule"
ACTUAL="${{ steps.create_entry.outputs.module-names }}"
if [[ "${ACTUAL}" != "${EXPECTED}" ]]; then
echo "Expected output module-names to be '${EXPECTED}' but it was '${ACTUAL}'"
exit 1
fi
EXPECTED="{module,submodule}@1.0.0"
ACTUAL="${{ steps.create_entry.outputs.short-description }}"
if [[ "${ACTUAL}" != "${EXPECTED}" ]]; then
echo "Expected output short-description to be '${EXPECTED}' but it was '${ACTUAL}'"
exit 1
fi