From 21e07c31975dd1364240aa8524269fdb81ee9f62 Mon Sep 17 00:00:00 2001
From: Divyanshu Agrawal <diagrawa@redhat.com>
Date: Wed, 17 Feb 2021 19:23:51 +0530
Subject: [PATCH] Add workflow, link checker and modify Readme (#30)

* Add test workflow for dockerfile build
* Add link checker workflow
* Modify Readme to divide input for build strategies

Signed-off-by: divyansh42 <diagrawa@redhat.com>
---
 .github/workflows/dockerfile_build.yml        |  45 ++++++
 .github/workflows/link_check.yml              |  18 +++
 .../{verify-build.yml => scratch_build.yml}   |   4 +-
 README.md                                     | 139 ++++--------------
 4 files changed, 91 insertions(+), 115 deletions(-)
 create mode 100644 .github/workflows/dockerfile_build.yml
 create mode 100644 .github/workflows/link_check.yml
 rename .github/workflows/{verify-build.yml => scratch_build.yml} (98%)

diff --git a/.github/workflows/dockerfile_build.yml b/.github/workflows/dockerfile_build.yml
new file mode 100644
index 0000000..91e7a0a
--- /dev/null
+++ b/.github/workflows/dockerfile_build.yml
@@ -0,0 +1,45 @@
+# This workflow will perform a test whenever there
+# is some change in code done to ensure that the changes
+# are not buggy and we are getting the desired output.
+name: Build from dockerfile
+on: [push, pull_request, workflow_dispatch]
+env:
+  IMAGE_NAME: "hello-world"
+
+jobs:
+  build:
+    name: Build image using Buildah
+    runs-on: ubuntu-20.04
+    steps:
+
+      # Checkout buildah action github repository
+      - name: Checkout Buildah action
+        uses: actions/checkout@v2
+        with:
+          path: "buildah-build"
+
+      - name: Create Dockerfile
+        run: |
+          cat > Dockerfile<<EOF
+          FROM busybox
+          RUN echo "hello world"
+          EOF
+
+      # Build image using Buildah action
+      - name: Build Image
+        id: build_image
+        uses: ./buildah-build/
+        with:
+          image: ${{ env.IMAGE_NAME }}
+          tags: 'latest ${{ github.sha }}'
+          dockerfiles: |
+            ./Dockerfile
+      
+      - name: Echo Outputs
+        run: | 
+          echo "Image: ${{ steps.build_image.outputs.image }}"
+          echo "Tags: ${{ steps.build_image.outputs.tags }}"
+
+      # Check if image is build
+      - name: Check images created
+        run: buildah images | grep '${{ env.IMAGE_NAME }}'
diff --git a/.github/workflows/link_check.yml b/.github/workflows/link_check.yml
new file mode 100644
index 0000000..88584a8
--- /dev/null
+++ b/.github/workflows/link_check.yml
@@ -0,0 +1,18 @@
+name: Link checker
+on:
+  push:
+    paths:
+      - '**.md'
+  pull_request:
+    paths:
+      -'**.md'
+
+jobs:
+  markdown-link-check:
+    name: Check links in markdown
+    runs-on: ubuntu-20.04
+    steps:
+      - uses: actions/checkout@v2
+      - uses: gaurav-nelson/github-action-markdown-link-check@v1
+        with:
+          use-verbose-mode: true
diff --git a/.github/workflows/verify-build.yml b/.github/workflows/scratch_build.yml
similarity index 98%
rename from .github/workflows/verify-build.yml
rename to .github/workflows/scratch_build.yml
index 9885cc6..4508981 100644
--- a/.github/workflows/verify-build.yml
+++ b/.github/workflows/scratch_build.yml
@@ -1,7 +1,7 @@
 # This workflow will perform a test whenever there
 # is some change in code done to ensure that the changes
 # are not buggy and we are getting the desired output.
-name: Test Build
+name: Build
 on: [push, pull_request, workflow_dispatch]
 env:
   PROJECT_DIR: spring-petclinic
@@ -11,7 +11,7 @@ env:
 jobs:
   build:
     name: Build image using Buildah
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
     steps:
 
       # Checkout buildah action github repository
diff --git a/README.md b/README.md
index 0ceef9b..85e133b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,8 @@
 # buildah-build
 [![CI checks](https://github.com/redhat-actions/buildah-build/workflows/CI%20checks/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22CI+checks%22)
-[![Verify Build](https://github.com/redhat-actions/buildah-build/workflows/Test%20Build/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Test+Build%22)
+[![Build](https://github.com/redhat-actions/buildah-build/workflows/Build/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3ABuild)
+[![Build from dockerfile](https://github.com/redhat-actions/buildah-build/workflows/Build%20from%20dockerfile/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Build+from+dockerfile%22)
+[![Link checker](https://github.com/redhat-actions/buildah-build/workflows/Link%20checker/badge.svg)](https://github.com/redhat-actions/buildah-build/actions?query=workflow%3A%22Link+checker%22)
 <br>
 <br>
 [![tag badge](https://img.shields.io/github/v/tag/redhat-actions/buildah-build)](https://github.com/redhat-actions/buildah-build/tags)
@@ -15,108 +17,31 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
 
 ## Action Inputs
 
-<table>
-  <thead>
-    <tr>
-      <th>Input</th>
-      <th>Required</th>
-      <th>Description</th>
-    </tr>
-  </thead>
+### Inputs for build from dockerfile
 
-  <tr>
-    <td>image</td>
-    <td>Yes</td>
-    <td>Name to give the output image.</td>
-  </tr>
+| Input Name | Description | Default |
+| ---------- | ----------- | ------- |
+| build-args | Build arguments to pass to the Docker build using `--build-arg`, if using a Dockerfile that requires ARGs. Use the form `arg_name=arg_value`, and separate arguments with newlines. | None
+| context | Path to directory to use as the build context. | `.`
+| dockerfiles | The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles. | **Must be provided**
+| image | Name to give to the output image. | **Must be provided**
+| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
+| tags | The tags of the image to build. For multiple tags, separate by a space. For example, `latest ${{ github.sha }}` | `latest`
 
-  <tr>
-    <td>tags</td>
-    <td>No</td>
-    <td>
-      The tags of the image to build. For multiple tags, separate by a space. For example, <code>latest ${{ github.sha }}</code>.<br>
-      Default: <code>latest</code>
-    </td>
-  </tr>
+### Inputs for build without dockerfile
 
-  <tr>
-    <td>base-image</td>
-    <td>No</td>
-    <td>The base image to use for the container.</td>
-  </tr>
-
-  <tr>
-    <td>dockerfiles</td>
-    <td>No</td>
-    <td>The list of Dockerfile paths to perform a build using docker instructions. This is a multiline input to allow multiple Dockerfiles.
-    </td>
-  </tr>
-
-  <tr>
-    <td>oci</td>
-    <td>No</td>
-    <td>
-      Build the image using the OCI format, instead of the Docker format.<br>
-      By default, this is <code>false</code>, because images built using the OCI format have <a href="https://github.com/docker/hub-feedback/issues/1871">issues</a> when published to Dockerhub.
-    </td>
-  </tr>
-
-  <tr>
-    <td>context</td>
-    <td>No</td>
-    <td>Path to directory to use as the build context.<br>
-    Default: <code>.</code></td>
-  </tr>
-
-  <tr>
-    <td>build-args</td>
-    <td>No</td>
-    <td>Build arguments to pass to the Docker build using <code>--build-arg</code>, if using a Dockerfile that requires ARGs.<br>
-    Uses the form <code>arg_name=arg_value</code>, and separate arguments with newlines.</td>
-  </tr>
-
-  <tr>
-    <td>content</td>
-    <td>No</td>
-    <td>The content to copy inside the container to create the final image. This is a multiline input to allow you to copy more than one file/directory.<br>
-    <pre>content: |
-  target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar</pre>
-    </td>
-  </tr>
-
-  <tr>
-    <td>entrypoint</td>
-    <td>No</td>
-    <td>The entry point to set for the container. This is a multiline input; split arguments across lines.
-      <pre>entrypoint: |
-  java
-  -jar
-  spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar</pre>
-    </td>
-  </tr>
-
-  <tr>
-    <td>port</td>
-    <td>No</td>
-    <td>The port to expose when running the container.</td>
-  </tr>
-
-  <tr>
-    <td>workdir</td>
-    <td>No</td>
-    <td>The working directory to use within the container.</td>
-  </tr>
-
-  <tr>
-    <td>envs</td>
-    <td>No</td>
-    <td>The environment variables to be set when running the container. This is a multiline input to add multiple environment variables.<br>
-      <pre>
-envs: |
-  GOPATH=/root/buildah/go</pre>
-    </td>
-  </tr>
-</table>
+| Input Name | Description | Default |
+| ---------- | ----------- | ------- |
+| base-image | The base image to use for the container. | **Must be provided**
+| content | Paths to files or directories to copy inside the container to create the file image. This is a multiline input to allow you to copy multiple files/directories.| None
+| context | Path to directory to use as the build context. | `.`
+| entrypoint | The entry point to set for the container. This is a multiline input; split arguments across lines. | None
+| envs | The environment variables to be set when running the container. This is a multiline input to add multiple environment variables. | None
+| image | Name to give to the output image. | **Must be provided**
+| oci | Build the image using the OCI format, instead of the Docker format. By default, this is `false`, because images built using the OCI format have issues when published to Dockerhub. | `false`
+| port | The port to expose when running the container. | None
+| tags | The tags of the image to build. For multiple tags, separate by a space. For example, `latest ${{ github.sha }}` | `latest`
+| workdir | The working directory to use within the container. | None
 
 ## Action Outputs
 
@@ -181,7 +106,7 @@ on: [push]
 
 jobs:
   build-image:
-    name: Build image
+    name: Build image without Dockerfile
     runs-on: ubuntu-latest
 
     steps:
@@ -209,15 +134,3 @@ For example:
 - name: Log in to Red Hat Registry
   run: echo "${{ secrets.REGISTRY_REDHAT_IO_PASSWORD }}" | docker login registry.redhat.io -u "${{ secrets.REGISTRY_REDHAT_IO_USER }}" --password-stdin
 ```
-
-## Contributing
-
-This is an open source project open to anyone. This project welcomes contributions and suggestions!
-
-## Feedback & Questions
-
-If you discover an issue please file a bug in [GitHub issues](https://github.com/redhat-actions/buildah/issues) and we will fix it as soon as possible.
-
-## License
-
-MIT, See [LICENSE](https://github.com/redhat-actions/buildah/blob/main/LICENSE.md) for more information.