From be27da5d0aac317a01498baabe3ac07055dabd28 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:54:50 +0100 Subject: [PATCH 1/4] feat: update to 1.17.0 plus big refactor --- .commitlintrc.json | 5 + .devcontainer/Dockerfile | 15 ++ .devcontainer/devcontainer.json | 14 ++ .dockerignore | 14 ++ .editorconfig | 8 +- .envrc | 7 + .github/CODEOWNERS | 4 + .github/dependabot.yml | 21 +++ .github/labels.yml | 21 +++ .github/release-drafter-config.yml | 56 +++++++ .github/workflows/ci.yml | 73 ++++----- .github/workflows/label-checker.yml | 29 ++++ .github/workflows/pr-title-checker.yml | 27 ++++ .github/workflows/release-drafter.yml | 27 ++++ .github/workflows/sync-labels.yml | 21 +++ .github/workflows/update-changelog.yml | 32 ++++ .gitignore | 2 + .hadolint.yml | 1 + .lefthook/commit-msg/commitlint.sh | 2 + .pre-commit-config.yaml | 12 -- .releaserc | 8 - .vscode/extensions.json | 3 + .yamllint | 8 - CHANGELOG.md | 1 + CONTRIBUTING.md | 108 ++++++++++++++ Dockerfile | 15 +- Makefile | 25 ---- README.md | 41 +---- Taskfile.yml | 29 ++++ devbox.json | 19 +++ devbox.lock | 197 +++++++++++++++++++++++++ lefthook.yml | 14 ++ structure-tests.yaml | 4 +- 33 files changed, 715 insertions(+), 148 deletions(-) create mode 100644 .commitlintrc.json create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .dockerignore create mode 100644 .envrc create mode 100644 .github/CODEOWNERS create mode 100644 .github/dependabot.yml create mode 100644 .github/labels.yml create mode 100644 .github/release-drafter-config.yml create mode 100644 .github/workflows/label-checker.yml create mode 100644 .github/workflows/pr-title-checker.yml create mode 100644 .github/workflows/release-drafter.yml create mode 100644 .github/workflows/sync-labels.yml create mode 100644 .github/workflows/update-changelog.yml create mode 100644 .gitignore create mode 100755 .lefthook/commit-msg/commitlint.sh delete mode 100644 .pre-commit-config.yaml delete mode 100644 .releaserc create mode 100644 .vscode/extensions.json delete mode 100644 .yamllint create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md delete mode 100644 Makefile create mode 100644 Taskfile.yml create mode 100644 devbox.json create mode 100644 devbox.lock create mode 100644 lefthook.yml diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 0000000..b34b410 --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,5 @@ +{ + "extends": [ + "@commitlint/config-conventional" + ] +} \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..daf54b7 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,15 @@ +FROM jetpackio/devbox:latest + +# Installing your devbox project +WORKDIR /code +USER root:root +RUN mkdir -p /code && chown ${DEVBOX_USER}:${DEVBOX_USER} /code +USER ${DEVBOX_USER}:${DEVBOX_USER} +COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.json devbox.json +COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.lock devbox.lock + + + +RUN devbox run -- echo "Installed Packages." + +RUN devbox shellenv --init-hook >> ~/.profile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..7c9afeb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,14 @@ +{ + "name": "Devbox Remote Container", + "build": { + "dockerfile": "./Dockerfile", + "context": ".." + }, + "customizations": { + "vscode": { + "settings": {}, + "extensions": ["jetpack-io.devbox", "task.vscode-task"] + } + }, + "remoteUser": "devbox" +} diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7e4ed87 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,14 @@ +.github +.devcontainer +.vscode +.lefthook +.commitlintrc.json +.editorconfig +.envrc +.env +.hadolint.yaml +CONTRIBUTING.md +Dockerfile +lefthook.yaml +structure-tests.yaml +Taskfile.yml diff --git a/.editorconfig b/.editorconfig index ed13cc7..3ca55b5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,18 +5,14 @@ charset = utf-8 end_of_line = lf trim_trailing_whitespace = true insert_final_newline = true -max_line_length = 80 +max_line_length = 120 [*.md] indent_style = space indent_size = 4 trim_trailing_whitespace = false -[Makefile] -indent_style = tab -indent_size = 4 - -[{Dockerfile,Dockerfile.template.erb,Dockerfile.sample}] +[Dockerfile] indent_style = space indent_size = 4 diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..84fc8e5 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +# Automatically sets up your devbox environment whenever you cd into this +# directory via our direnv integration: + +eval "$(devbox generate direnv --print-envrc)" + +# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/ +# for more details diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..f4cd004 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,4 @@ +# This is a CODEOWNERS file. +# Each line is a file pattern followed by one or more owners. + +* @brpaz diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..61a11fc --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +updates: + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "weekly" + reviewers: + - "brpaz" + open-pull-requests-limit: 5 + labels: + - "dependencies" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + reviewers: + - "brpaz" + open-pull-requests-limit: 3 + labels: + - "dependencies" diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..7d36026 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,21 @@ +- name: bug + description: Something isn't working + color: d73a4a +- name: documentation + description: Improvements or additions to documentation + color: 0075ca +- name: duplicate + description: This issue or pull request already exists + color: cfd3d7 +- name: security + description: Security updates + color: a31f34 +- name: feature + description: New feature + color: 0e8a16 +- name: enhancement + description: Enhancement on existing Feature + color: 0e8a16 +- name: chore + description: Maintenance + color: F6EE8F diff --git a/.github/release-drafter-config.yml b/.github/release-drafter-config.yml new file mode 100644 index 0000000..7415214 --- /dev/null +++ b/.github/release-drafter-config.yml @@ -0,0 +1,56 @@ +name-template: "$RESOLVED_VERSION" +tag-template: "$RESOLVED_VERSION" +categories: + - title: "Breaking Changes" + labels: + - breaking + - title: πŸš€ Features + labels: + - feature + - enhancement + - title: πŸ› Bug Fixes + labels: + - bug + - title: πŸ” Security updates + labels: + - security + - title: ⚠️ Maintenance + labels: + - chore + - maintenance + - title: πŸ“„ Documentation + labels: + - docs + - documentation + - title: 🧩 Dependency Updates + labels: + - deps + - dependencies + collapse-after: 5 +change-template: "- $TITLE @$AUTHOR (#$NUMBER)" +change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks. +exclude-labels: + - "skip-changelog" +version-resolver: + major: + labels: + - "breaking" + minor: + labels: + - feature + - enhancement + patch: + labels: + - "bug" + - "maintenance" + - "chore" + - "dependencies" + - "deps" + - "security" + - "docs" +template: | + # What's Changed + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a60332..6b15d13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,65 +4,46 @@ on: branches: - master pull_request: + release: + types: [published] env: - TEST_IMAGE_NAME: structure-tests-action:${{github.sha}} + TEST_IMAGE_TAG: structure-tests-action:test jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: brpaz/hadolint-action@master - build: - runs-on: ubuntu-latest - needs: ['lint'] - steps: - - uses: actions/checkout@v1 - - name: Build Docker image - run: docker build -t $TEST_IMAGE_NAME . - - - name: Save Docker image artifact - run: docker save -o action.tar $TEST_IMAGE_NAME + - uses: actions/checkout@v4 - - name: Upload image artifact - uses: actions/upload-artifact@master + - name: Lint Dockerfile + uses: hadolint/hadolint-action@v3.1.0 with: - name: action-image - path: action.tar + dockerfile: Dockerfile - test: - name: Unit Tests + build: + name: Build and Test runs-on: ubuntu-latest - needs: build + needs: [lint] steps: - - uses: actions/checkout@v1 - - name: Pull Image artifact - uses: actions/download-artifact@master - with: - name: action-image + - name: Checkout + uses: actions/checkout@v4 - - name: Load image into docker context - run: docker load -i action-image/action.tar + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Get Image name - id: image_name - run: echo "##[set-output name=image;]$(echo $TEST_IMAGE_NAME)" + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Run Structure tests - uses: ./ + - name: Build test image + uses: docker/build-push-action@v5 with: - configFile: 'structure-tests.yaml' - image: ${{steps.image_name.outputs.image}} - - release: - if: github.event_name == 'push' && github.ref == 'refs/heads/master' - name: Release - runs-on: ubuntu-latest - needs: test - steps: - - uses: actions/checkout@v1 - - name: Semantic Release - uses: brpaz/action-semantic-release@v1 - env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + context: . + load: true + tags: ${{ env.TEST_IMAGE_TAG }} + + - name: Run tests + run: | + container-structure-test test \ + --image ${{ env.TEST_IMAGE_TAG }} \ + --config structure-test.yaml diff --git a/.github/workflows/label-checker.yml b/.github/workflows/label-checker.yml new file mode 100644 index 0000000..d22652c --- /dev/null +++ b/.github/workflows/label-checker.yml @@ -0,0 +1,29 @@ +name: Label Checker + +on: + pull_request: + types: + - opened + - synchronize + - reopened + - labeled + - unlabeled + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: read + checks: write + +jobs: + check_cc_labels: + name: Check conventional commits labels + runs-on: "ubuntu-latest" + steps: + - uses: danielchabr/pr-labels-checker@v3.3 + with: + hasSome: feature,fix,changed,deprecated,security,docs,dependencies + githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr-title-checker.yml b/.github/workflows/pr-title-checker.yml new file mode 100644 index 0000000..df9f25c --- /dev/null +++ b/.github/workflows/pr-title-checker.yml @@ -0,0 +1,27 @@ +name: Check PR title + +on: + pull_request: + types: + - opened + - reopened + - edited + - synchronize + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +permissions: + contents: read + statuses: write + +jobs: + title-checker: + name: Check PR title + runs-on: ubuntu-latest + + steps: + - uses: aslafy-z/conventional-pr-title-action@v3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..256e6b5 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,27 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - main + # pull_request event is required only for autolabeler + pull_request: + # Only following types are handled by the action, but one can default to all as well + types: [opened, reopened, synchronize] + +jobs: + update_release_draft: + permissions: + # write permission is required to create a github release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v6 + with: + config-name: release-drafter-config.yml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml new file mode 100644 index 0000000..83ead9e --- /dev/null +++ b/.github/workflows/sync-labels.yml @@ -0,0 +1,21 @@ +name: Sync labels +on: + push: + branches: + - main + paths: + - .github/labels.yml + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: micnncim/action-label-syncer@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + manifest: .github/labels.yml diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..1352ea3 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,32 @@ +name: Release + +on: + release: + types: [published] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + changelog: + name: Update Changelog + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.tag_name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit release files + uses: stefanzweifel/git-auto-commit-action@v5 + with: + branch: main + commit_message: "chore(release): [skip-ci] ${{ github.event.release.tag_name }}" + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c875e1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.devbox +.env diff --git a/.hadolint.yml b/.hadolint.yml index 784711c..9388e27 100644 --- a/.hadolint.yml +++ b/.hadolint.yml @@ -2,4 +2,5 @@ # configure ignore rules # see https://github.com/hadolint/hadolint#rules for a list of available rules. +failure-threshold: error ignored: [] diff --git a/.lefthook/commit-msg/commitlint.sh b/.lefthook/commit-msg/commitlint.sh new file mode 100755 index 0000000..069f43b --- /dev/null +++ b/.lefthook/commit-msg/commitlint.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +echo $(head -n1 $1) | commitlint --color diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 1529807..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -- repo: local - hooks: - - id: lint-dockerfile - name: Lint Dockerfile - entry: make lint-dockerfile - language: system - files: \.yml$ - - id: lint-yaml - name: Lint YAML - entry: make lint-yaml - language: system - files: \.yml$ diff --git a/.releaserc b/.releaserc deleted file mode 100644 index 30c79c7..0000000 --- a/.releaserc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "plugins": [ - "@semantic-release/commit-analyzer", - "@semantic-release/release-notes-generator", - "@semantic-release/git", - "@semantic-release/github" - ] -} diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..fdf47ee --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["task.vscode-task", "jetpack-io.devbox"] +} diff --git a/.yamllint b/.yamllint deleted file mode 100644 index 39a5255..0000000 --- a/.yamllint +++ /dev/null @@ -1,8 +0,0 @@ -extends: default - -rules: - # 80 chars should be enough, but don't fail if a line is longer - line-length: - max: 80 - level: warning - document-start: disable diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..825c32f --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..0c6d676 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,108 @@ +# Contributing guidelines + +Welcome to our project's contribution guidelines! We're thrilled that you're interested in contributing to our repository. + +This document outlines the process for making contributions to our project, whether you're fixing a bug, implementing a new feature, or suggesting improvements. Please take a moment to review these guidelines before diving into your contributions. Your participation is invaluable, and we appreciate your efforts to make our project better for everyone. + +Let's build something great together! + +- [Contributing guidelines](#contributing-guidelines) + - [Reporting issues](#reporting-issues) + - [Contribute with code](#contribute-with-code) + - [Setup development envrionment](#setup-development-envrionment) + - [Using Devbox](#using-devbox) + - [Using dev containers](#using-dev-containers) + - [Tools we use](#tools-we-use) + - [Development lifecycle](#development-lifecycle) + - [Submitting your changes for review](#submitting-your-changes-for-review) + - [Commit guidelines](#commit-guidelines) + - [Release process](#release-process) + + +## Reporting issues + +If you found any issue, feel free to submit a [GitHub issue](https://github.com/brpaz/structure-tests-action) + +Before submitting a new issue, we encourage you to utilize the search functionality to check if a similar issue has already been reported. This ensures that we avoid duplication and allows us to focus on addressing unique problems effectively. + +When creating a new issue, please provide the most information you can like application version, operating system, logs and stack traces and anything else that you think is relevant and can help the investigation process. + +## Contribute with code + +If you are a developer, and want to contribute with the code, please follow the next steps, to understand how to setup the development envrionment and our release process. + +### Setup development envrionment + +#### Using Devbox + +The easiest way to setup this project on your local machine is to use [devbox](https://github.com/jetify-com/devbox). + +Devbox is a command-line tool that lets you easily create isolated shells for development. You start by defining the list of packages required for your project, and Devbox creates an isolated, reproducible environment with those packages installed, using the powerfull [Nix](https://nixos.org/) under the hood. + +You can install it using the following command: +```sh +curl -fsSL https://get.jetpack.io/devbox | bash +``` + +Then run `devbox shell` to start a shell, with all the tools installed by devbox. + +> [!TIP] +> To learn more about Devbox, check the [Introduction guide](https://www.jetify.com/devbox/docs/) on Devbox website. + + +#### Using dev containers + +If you use VSCode or GitHub Codespaces, we also provide a [Devcontainer](https://containers.dev/) definition that you can use. ItΒ΄s simply a wrapper for Devbox, but allows to start coding right way, without even installing Devbox on your machine. + +### Tools we use + +- [Task](https://taskfile.dev/) a task runner / build tool, modern alternative to Make. Useful to define common tasks like build the application or run the tests. Run `task -l` or check [Taskfile.yml](Taskfile.yml) to see the available tasks. +- [lefthook](https://github.com/evilmartians/lefthook) - Fast and powerful Git hooks manager for any type of projects. Useful to run tasks like linting and formatting, before commiting changes GitHub. +- [commitlint](https://commitlint.js.org/) - Lint commit messages ensuring a standard structure acorss all commits. + +### Development lifecycle + +This project follows [GitHub flow](https://docs.github.com/en/get-started/using-github/github-flow) for managing changes. + +When implmenting a new feature, start by creating a new branch from `main`, with a descriptive name (Ex: `feat/my-awesome-feature` or `fix/some-bug`). + +Having a descriptive name helps to reason about the branches, when you have many. + +Checkout to that branch and do your changes. + +Some useful guidelines when working on feature branches: + +- **keep it short lived** - Long running feature branches can lead to problems, like merge conflicts. You should aim to create a feature branch, for a feature than is small enough to be done in a few days. +- **rebase with main at least once a day** - this ensure you are always working with the most recent code and allows to fix any conflicts that might occurr, early in the process. + +#### Submitting your changes for review + +When you are ready create a Pull request to the main branch. + +When creating a pull request, you should: + +- Provide a descriptive PR title, following [Conventional Commits](https://www.conventionalcommits.org/en/) specification. +- Provide a short description of what changes you did, core architecture decisions you took, and link to any issue the PR might relate to. +- Ensure that any automated checks like Linting and Tests pass. + +The PR will then be reviewed and changes may by requested. Keep commiting those changes, until the PR is approved. + +After being approved, the maintainers will merge the PR to main branch and start the release process. + +#### Commit guidelines + +The project folows [Conventional Commits](https://www.conventionalcommits.org/en/) specification. + +Each commit message should begin with a type, indicating the nature of the change (e.g., feat for a new feature, fix for a bug fix, docs for documentation changes), followed by a concise and descriptive message. + +Additionally, providing an optional scope and further details in the commit message body is encouraged when necessary. This approach streamlines the review process, facilitates automated release notes generation, and enhances overall project maintainability. + +We also recommend squashing your commits when appropriate. + +## Release process + +We use [Release Drafter](https://github.com/marketplace/actions/release-drafter) to automatically create draft releases with appropriate release notes, anytime a PR is merged. + +When we are ready to create a new release, we simply publish the release, which will trigger GitHub actions, that will publish any related artifacts and commit a Changelog to the project repository. + + diff --git a/Dockerfile b/Dockerfile index c2d580d..e8870d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,15 @@ -FROM alpine:3.15 +FROM alpine:3.19 -ARG STRUCTURE_TEST_VERSION=1.11.0 +ARG STRUCTURE_TEST_VERSION=1.17.0 +ENV STRUCTURE_TEST_VERSION=${STRUCTURE_TEST_VERSION} +ENV DOWNLOAD_URL=https://github.com/GoogleContainerTools/container-structure-test/releases/download/v${STRUCTURE_TEST_VERSION}/container-structure-test-linux-amd64 -RUN apk add --no-cache curl~=7 git~=2 +RUN apk add --no-cache curl -RUN curl -LO https://storage.googleapis.com/container-structure-test/v$STRUCTURE_TEST_VERSION/container-structure-test-linux-amd64 && chmod +x container-structure-test-linux-amd64 && mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test - -COPY LICENSE README.md / +RUN curl -LO ${DOWNLOAD_URL} \ + && chmod +x container-structure-test-linux-amd64 \ + && mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test \ + && container-structure-test version COPY entrypoint.sh /entrypoint.sh diff --git a/Makefile b/Makefile deleted file mode 100644 index c1fa99c..0000000 --- a/Makefile +++ /dev/null @@ -1,25 +0,0 @@ - -IMAGE_NAME:=structure-tests-action - -lint-dockerfile: ## Runs hadoint against application dockerfile - @docker run --rm -v "$(PWD):/data" -w "/data" hadolint/hadolint hadolint Dockerfile - -lint-yaml: ## Lints yaml configurations - @docker run --rm -v "$(PWD):/yaml" sdesbure/yamllint yamllint . - -build: ## Builds the docker image - @docker build . -t $(IMAGE_NAME) - -test: build ## Runs a test in the image - @docker run -i --rm \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v ${PWD}:/test zemanlx/container-structure-test:v1.9.1-alpine \ - test \ - --image $(IMAGE_NAME) \ - --config test/structure-tests.yaml - -help: - @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' - -.DEFAULT_GOAL := help -.PHONY: lint build test help diff --git a/README.md b/README.md index bea9c73..9decceb 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ [![GitHub Action](https://img.shields.io/badge/GitHub-Action-blue?style=for-the-badge)](https://github.com/features/actions) [![License](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](LICENSE) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=for-the-badge)](http://commitizen.github.io/cz-cli/) -[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge)](https://github.com/semantic-release/semantic-release?style=for-the-badge) - [![GitHub Actions](https://github.com/brpaz/structure-tests-action/workflows/CI/badge.svg?style=for-the-badge)](https://github.com/brpaz/structure-tests-action/actions) @@ -33,48 +31,21 @@ steps: ## 🀝 Contributing -Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. - -1. Fork the Project -2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) -3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) -4. Push to the Branch (`git push origin feature/AmazingFeature`) -5. Open a Pull Request - -## Useful Resources - -* [Building actions - GitHub Help](https://help.github.com/en/articles/building-actions) -* [actions/toolkit: The GitHub ToolKit for developing GitHub Actions.](https://github.com/actions/toolkit) - -## FAQ +Check [CONTRIBUTING.md](CONTRIBUTING.md) for details. -
- How can I use an envrionment variable as input -

+## 🫢 Support -Using Environment variables directly as input arguments is not supported by GitHub Actions. -You can define an intermidiate step that outputs the desired value and use that value as the input +If you find this project helpful and would like to support its development, there are a few ways you can contribute: -```yaml -- name: Get Image name - id: image_name - run: echo "##[set-output name=image;]$(echo $TEST_IMAGE_NAME)" -``` - -And then use it as input: - -```sh -image: ${{steps.image_name.outputs.image}} -``` +[![Sponsor me on GitHub](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=red&&style=for-the-badge&labelColor=white)](https://github.com/sponsors/brpaz) -

-
+Buy Me A Coffee ## Author πŸ‘€ **Bruno Paz** -* authorWebsite: [https://github.com/brpaz](https://github.com/brpaz) +* Website: [https://github.com/brpaz](https://github.com/brpaz) * Github: [@brpaz](https://github.com/brpaz) ## πŸ“ License diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..785b790 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,29 @@ +version: "3" + +env: + TEST_IMAGE_TAG: "action-structure-tests:dev" + +tasks: + default: + cmds: + - task -l + + lint: + desc: "Runs hadolint against application dockerfile" + cmds: + - hadolint Dockerfile + + build: + desc: "Builds the docker image" + cmds: + - docker build . -t {{ .TEST_IMAGE_TAG }} + + test: + desc: "Runs a test in the image" + deps: + - build + cmds: + - | + container-structure-test test \ + --image {{ .TEST_IMAGE_TAG }} \ + --config structure-tests.yaml diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..910f031 --- /dev/null +++ b/devbox.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.10.5/.schema/devbox.schema.json", + "packages": [ + "go-task@3.36.0", + "lefthook@1.6.1", + "hadolint@2.12.0", + "commitlint@19.2.0" + ], + "shell": { + "init_hook": [ + "lefthook install" + ], + "scripts": { + "test": [ + "echo \"Error: no test specified\" && exit 1" + ] + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 0000000..a6d4f44 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,197 @@ +{ + "lockfile_version": "1", + "packages": { + "commitlint@19.2.0": { + "last_modified": "2024-04-19T17:36:04-04:00", + "resolved": "github:NixOS/nixpkgs/92d295f588631b0db2da509f381b4fb1e74173c5#commitlint", + "source": "devbox-search", + "version": "19.2.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/pjv1aqyf4ji9wm13l0rr7mrpplx8lww0-_at_commitlint_slash_cli-19.2.0", + "default": true + } + ], + "store_path": "/nix/store/pjv1aqyf4ji9wm13l0rr7mrpplx8lww0-_at_commitlint_slash_cli-19.2.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/salaps1x6wc9r5alih2yg93zaqmmzxrj-_at_commitlint_slash_cli-19.2.0", + "default": true + } + ], + "store_path": "/nix/store/salaps1x6wc9r5alih2yg93zaqmmzxrj-_at_commitlint_slash_cli-19.2.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/33ya418shkk9vjnd9pp1x3k41x5f2888-_at_commitlint_slash_cli-19.2.0", + "default": true + } + ], + "store_path": "/nix/store/33ya418shkk9vjnd9pp1x3k41x5f2888-_at_commitlint_slash_cli-19.2.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/ycq2afp079gcdf2p3yn7w0g58yxlxbax-_at_commitlint_slash_cli-19.2.0", + "default": true + } + ], + "store_path": "/nix/store/ycq2afp079gcdf2p3yn7w0g58yxlxbax-_at_commitlint_slash_cli-19.2.0" + } + } + }, + "go-task@3.36.0": { + "last_modified": "2024-04-19T17:36:04-04:00", + "resolved": "github:NixOS/nixpkgs/92d295f588631b0db2da509f381b4fb1e74173c5#go-task", + "source": "devbox-search", + "version": "3.36.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/s7999mjjjkan5fi20csad6pxha0pcn9m-go-task-3.36.0", + "default": true + } + ], + "store_path": "/nix/store/s7999mjjjkan5fi20csad6pxha0pcn9m-go-task-3.36.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/pf3rrjy7d7hl9b9qrlqfs7r0dp1c9gl2-go-task-3.36.0", + "default": true + } + ], + "store_path": "/nix/store/pf3rrjy7d7hl9b9qrlqfs7r0dp1c9gl2-go-task-3.36.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/crv84dwq688wdwlw165b52yk8zshs3zz-go-task-3.36.0", + "default": true + } + ], + "store_path": "/nix/store/crv84dwq688wdwlw165b52yk8zshs3zz-go-task-3.36.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/g1chzl549g4jzjpaqc1i2d0hbazkhx5l-go-task-3.36.0", + "default": true + } + ], + "store_path": "/nix/store/g1chzl549g4jzjpaqc1i2d0hbazkhx5l-go-task-3.36.0" + } + } + }, + "hadolint@2.12.0": { + "last_modified": "2024-04-19T17:36:04-04:00", + "resolved": "github:NixOS/nixpkgs/92d295f588631b0db2da509f381b4fb1e74173c5#hadolint", + "source": "devbox-search", + "version": "2.12.0", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/4ms8mv7xgwdxsg7n9829kzcm2g6dqsci-hadolint-2.12.0", + "default": true + } + ], + "store_path": "/nix/store/4ms8mv7xgwdxsg7n9829kzcm2g6dqsci-hadolint-2.12.0" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/0qa29xzhgxx7zff6xllym5vdfj2qrbxs-hadolint-2.12.0", + "default": true + } + ], + "store_path": "/nix/store/0qa29xzhgxx7zff6xllym5vdfj2qrbxs-hadolint-2.12.0" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/nav0w98y70jj9l33ak4ql0ifn0zhxhcg-hadolint-2.12.0", + "default": true + } + ], + "store_path": "/nix/store/nav0w98y70jj9l33ak4ql0ifn0zhxhcg-hadolint-2.12.0" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/jf4qh06cr6qfrya74pfj9jckj679wvh0-hadolint-2.12.0", + "default": true + } + ], + "store_path": "/nix/store/jf4qh06cr6qfrya74pfj9jckj679wvh0-hadolint-2.12.0" + } + } + }, + "lefthook@1.6.1": { + "last_modified": "2024-04-19T17:36:04-04:00", + "resolved": "github:NixOS/nixpkgs/92d295f588631b0db2da509f381b4fb1e74173c5#lefthook", + "source": "devbox-search", + "version": "1.6.10", + "systems": { + "aarch64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/rcc1145skrkam515r8c7y858fjmpqd1a-lefthook-1.6.10", + "default": true + } + ], + "store_path": "/nix/store/rcc1145skrkam515r8c7y858fjmpqd1a-lefthook-1.6.10" + }, + "aarch64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/yg94l16sf0vmbc0w44axdnnq39h14i28-lefthook-1.6.10", + "default": true + } + ], + "store_path": "/nix/store/yg94l16sf0vmbc0w44axdnnq39h14i28-lefthook-1.6.10" + }, + "x86_64-darwin": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/dpblwbiynqp0zxbsxk78vy6masjdys27-lefthook-1.6.10", + "default": true + } + ], + "store_path": "/nix/store/dpblwbiynqp0zxbsxk78vy6masjdys27-lefthook-1.6.10" + }, + "x86_64-linux": { + "outputs": [ + { + "name": "out", + "path": "/nix/store/x5g93raw3xyyndr5mj9z1qmc8isgmj8h-lefthook-1.6.10", + "default": true + } + ], + "store_path": "/nix/store/x5g93raw3xyyndr5mj9z1qmc8isgmj8h-lefthook-1.6.10" + } + } + } + } +} diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..7c5dc18 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,14 @@ +# EXAMPLE USAGE: +# +# Refer for explanation to following link: +# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md +# + +pre-commit: + parallel: true + commands: + lint: + run: task lint + scripts: + "commitlint.sh": + runner: bash diff --git a/structure-tests.yaml b/structure-tests.yaml index 0c8985c..b91ec35 100644 --- a/structure-tests.yaml +++ b/structure-tests.yaml @@ -1,11 +1,11 @@ schemaVersion: 2.0.0 metadataTest: - entrypoint: ['/entrypoint.sh'] + entrypoint: ["/entrypoint.sh"] commandTests: - name: "Check Container structure test is installed" command: container-structure-test args: [version] exitCode: 0 - expectedOutput: ["v1.11.0"] + expectedOutput: ["v1.17.0"] From 076109383ad6af3fefec7c230a707a83a0088bae Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Fri, 26 Apr 2024 15:58:41 +0100 Subject: [PATCH 2/4] ci(github-actions): install structure-test from github --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b15d13..dafe4a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,6 +42,13 @@ jobs: load: true tags: ${{ env.TEST_IMAGE_TAG }} + - name: Install container-structure-test + run: | + curl -LO https://github.com/GoogleContainerTools/container-structure-test/releases/download/v1.17.0 \ + && chmod +x container-structure-test-linux-amd64 \ + && mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test \ + && container-structure-test version + - name: Run tests run: | container-structure-test test \ From 7ae85614f80b2a537cf0196c3b190bb663cb9258 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:00:56 +0100 Subject: [PATCH 3/4] ci(github-actions): install structure-test from github --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dafe4a1..e305278 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,7 +44,7 @@ jobs: - name: Install container-structure-test run: | - curl -LO https://github.com/GoogleContainerTools/container-structure-test/releases/download/v1.17.0 \ + curl -LO https://github.com/GoogleContainerTools/container-structure-test/releases/download/v1.17.0/container-structure-test-linux-amd64 \ && chmod +x container-structure-test-linux-amd64 \ && mv container-structure-test-linux-amd64 /usr/local/bin/container-structure-test \ && container-structure-test version From 0a695df32d5888db9ffb1c32485637037d729406 Mon Sep 17 00:00:00 2001 From: Bruno Paz <184563+brpaz@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:02:47 +0100 Subject: [PATCH 4/4] ci(github-actions): install structure-test from github --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e305278..3f6e03d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,4 +53,4 @@ jobs: run: | container-structure-test test \ --image ${{ env.TEST_IMAGE_TAG }} \ - --config structure-test.yaml + --config structure-tests.yaml