-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See also: - https://github.com/GoogleContainerTools/container-structure-test - https://github.com/actions/cache - https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions - https://haya14busa.github.io/github-action-brandings/
- Loading branch information
1 parent
02f74b3
commit 5f6a944
Showing
9 changed files
with
333 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# EditorConfig: https://EditorConfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# | ||
# https://help.github.com/articles/dealing-with-line-endings/ | ||
# | ||
# Set the default behavior, in case people don't have core.autocrlf set. | ||
* text=auto | ||
|
||
# These are explicitly windows files and should use crlf | ||
*.bat text eol=crlf | ||
|
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @beiertu-mms |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM alpine:3 | ||
|
||
RUN apk --no-cache add bash jq curl | ||
|
||
ENTRYPOINT [ "/bin/bash" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
schemaVersion: 2.0.0 | ||
|
||
commandTests: | ||
- name: 'bash' | ||
command: 'bash' | ||
args: ['--help'] | ||
expectedOutput: | ||
- '.*GNU bash.*' | ||
- name: 'jq' | ||
command: 'jq' | ||
args: ['--help'] | ||
expectedOutput: | ||
- '.*commandline JSON processor.*' | ||
- name: 'curl' | ||
command: 'curl' | ||
args: ['--help'] | ||
expectedOutput: | ||
- '.*Usage: curl.*' | ||
|
||
metadataTest: | ||
entrypoint: ['/bin/bash'] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
name: Tag latest commit | ||
"on": | ||
release: | ||
types: | ||
- "published" | ||
|
||
jobs: | ||
tag_latest_commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ssh-key: "${{ secrets.COMMIT_KEY }}" | ||
fetch-depth: 0 | ||
|
||
- run: | | ||
version="${GITHUB_REF#refs/tags/}" | ||
major_version=$(echo "$version" | cut -d'.' -f1) | ||
echo "this release $GITHUB_REF major version is: $major_version" | ||
echo -e "\nlist all remote tags" | ||
git ls-remote --tags | ||
if git tag --delete "$major_version"; then | ||
git push origin --delete "$major_version" | ||
else | ||
echo "$major_version has not been used yet" | ||
fi | ||
echo -e "\nconfigure commiter" | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
echo -e "\ntag latest commit with $major_version" | ||
git tag --annotate "$major_version" --message "$major_version" "$GITHUB_SHA" | ||
echo -e "\npush $major_version to remote" | ||
git push origin "$major_version" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
name: "Test action" | ||
"on": | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
env: | ||
test_folder: .github/test | ||
image: actungs/test-image:local | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: docker/setup-buildx-action@v3 | ||
|
||
- uses: docker/build-push-action@v5 | ||
with: | ||
load: true | ||
context: ${{ env.test_folder }} | ||
tags: ${{ env.image }} | ||
|
||
- uses: actungs/container-structure-test-action@master | ||
with: | ||
image: ${{ env.image }} | ||
config_files: ${{ env.test_folder }}/config.yaml | ||
output_format: json | ||
report_file: result.json | ||
|
||
- run: | | ||
echo "Result:" | ||
jq . result.json | ||
if [[ $(jq '.Fail' result.json) != 0 ]]; then | ||
echo "Expect Fail to be 0." | ||
exit 1 | ||
fi | ||
if [[ $(jq '.Pass' result.json) != 4 ]]; then | ||
echo "Expect Pass to be 4." | ||
exit 1 | ||
fi | ||
actual_result_names=$(jq -r '.Results | sort_by(.Name) | .[].Name' result.json | tr "\n" ";") | ||
if [[ "$actual_result_names" != 'Command Test: bash;Command Test: curl;Command Test: jq;Metadata Test;' ]]; then | ||
echo "Expect Results.Name to be ''" | ||
exit 1 | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,84 @@ | ||
# container-structure-test-action | ||
An action to setup the container-structure-test executable. | ||
# Container Structure Test Action | ||
|
||
An action to setup, cache and run the [GoogleContainerTools/container-structure-test](https://github.com/GoogleContainerTools/container-structure-test) executable. | ||
|
||
[actions/cache](https://github.com/actions/cache) is used to cache the executable under `<OS name>-container-structure-test`. | ||
|
||
The cache should be deleted if the executable should be re-installed. | ||
|
||
> [!NOTE] | ||
> Currently this action only supports Linux and macOS GitHub runners. | ||
## Usage | ||
|
||
```yaml | ||
- uses: actungs/container-structure-test-action@v1 | ||
with: | ||
# The full docker image tag to be verified. | ||
# | ||
# Required. | ||
image: '' | ||
|
||
# The path to the container structure configuration files. | ||
# | ||
# Required. | ||
config_files: '' | ||
|
||
# The version of container-structure-test to be installed. | ||
# See the key property in https://storage.googleapis.com/container-structure-test for available versions. | ||
# | ||
# Default: 'latest' | ||
version: '' | ||
|
||
# The path to where the executable will be installed to. | ||
# | ||
# Default: '.bin' | ||
install_path: '' | ||
|
||
# Set to 'false' if color should be used in the output. | ||
# | ||
# Default: 'true' | ||
no_color: '' | ||
|
||
# Set to 'true' to force a pull of the image before running the tests. | ||
# | ||
# Default: 'false' | ||
pull_image: '' | ||
|
||
# The output format for the test report. Available format: text, json, junit. | ||
# | ||
# Default: 'text' | ||
output_format: '' | ||
|
||
# Write the test report to the specified file. Supported file types are json and junit. | ||
# Set the `output_format` accordingly. | ||
# If the `output_format` does not match the given file type, then `json` will be used instead. | ||
# | ||
# Default: '' | ||
report_file: '' | ||
``` | ||
|
||
## Example | ||
|
||
A simplified example, on how this action can be utilized, could look like this. | ||
|
||
```yaml | ||
"on": [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# Build the container image | ||
# ... | ||
# Run the container test, assuming the image is 'actungs/test-image:local' and the configuration file is 'config.yaml'. | ||
- uses: actungs/container-structure-test-action@v1 | ||
with: | ||
image: actungs/test-image:local | ||
config_files: config.yaml | ||
``` | ||
|
||
## License | ||
|
||
This project is released under the [MIT License](./LICENSE). | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
--- | ||
name: "Container Structure Test Action" | ||
description: "A composite action to verify a container structure using GoogleContainerTools/container-structure-test." | ||
branding: | ||
icon: 'check' | ||
color: 'blue' | ||
inputs: | ||
image: | ||
description: | | ||
The full docker image tag to be verified. | ||
required: true | ||
config_files: | ||
description: | | ||
The path to the container structure configuration file. | ||
required: true | ||
version: | ||
description: | | ||
The version of container-structure-test to be installed. | ||
Default to 'latest' if not provided. | ||
See the key property in https://storage.googleapis.com/container-structure-test for available versions. | ||
required: false | ||
default: "latest" | ||
install_path: | ||
description: | | ||
The path to where the executable will be installed to. | ||
required: false | ||
default: ".bin" | ||
no_color: | ||
description: | | ||
No color in the output. | ||
required: false | ||
default: "true" | ||
pull_image: | ||
description: | | ||
Whether the image should be pulled instead. | ||
required: false | ||
default: "false" | ||
output_format: | ||
description: | | ||
The output format for the test report. | ||
Available format: text, json, junit | ||
Default: text | ||
default: "text" | ||
report_file: | ||
description: | | ||
Write the test report to the specified file. Supported file types are json and junit. | ||
default: "" | ||
runs: | ||
using: "composite" | ||
steps: | ||
- uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: ${{ inputs.install_path }} | ||
key: ${{ runner.os }}-container-structure-test | ||
restore-keys: | | ||
${{ runner.os }}-container-structure-test | ||
- run: | | ||
if [[ "${{ steps.cache.outputs.cache-hit }}" == 'true' ]]; then | ||
echo "container-structure-test found in cache. It will not be installed for this run." | ||
else | ||
echo "container-structure-test not found in cache. ${{ inputs.version }} version will be installed." | ||
case "$RUNNER_OS" in | ||
Linux) | ||
curl --location \ | ||
--output container-structure-test \ | ||
"https://storage.googleapis.com/container-structure-test/${{ inputs.version }}/container-structure-test-linux-amd64" | ||
;; | ||
macOS) | ||
curl --location \ | ||
--output container-structure-test \ | ||
"https://storage.googleapis.com/container-structure-test/${{ inputs.version }}/container-structure-test-darwin-amd64" | ||
;; | ||
*) | ||
echo "$RUNNER_OS is not supported! Use a linux or macOs one instead." | ||
exit 1 | ||
;; | ||
esac | ||
mkdir -vp "./${{ inputs.install_path }}" | ||
chmod +x container-structure-test | ||
mv -v container-structure-test "./${{ inputs.install_path }}/container-structure-test" | ||
fi | ||
echo "./${{ inputs.install_path }}" >> "$GITHUB_PATH" | ||
shell: bash | ||
- run: | | ||
NO_COLOR="" | ||
[[ "${{ inputs.no_color }}" == 'true' ]] && NO_COLOR="--no-color" | ||
PULL_IMAGE="" | ||
[[ "${{ inputs.pull_image }}" == 'true' ]] && PULL_IMAGE="--pull" | ||
OUTPUT_FORMAT="--output ${{ inputs.output_format }}" | ||
REPORT_FILE="" | ||
[[ -n "${{ inputs.report_file }}" ]] && REPORT_FILE="--test-report ${{ inputs.report_file }}" | ||
container-structure-test test $NO_COLOR $PULL_IMAGE $OUTPUT_FORMAT $REPORT_FILE \ | ||
--image "${{ inputs.image }}" \ | ||
--config "${{ inputs.config_files }}" | ||
shell: bash |