Skip to content

Commit

Permalink
BREAKING CHANGE: Use a built Docker image (#28)
Browse files Browse the repository at this point in the history
- Build and push a Docker image rather than requiring the user built it
  every time
- Move some of the entrypoint to correct COPY and ENV statements
- Chmod and copy at the same time as we're now using buildx
- Use Ruby slim
- Use specific version numbers for Ruby & mdl so renovate will bump the
  version numbers

Signed-off-by: Dan Webb <[email protected]>
  • Loading branch information
damacus authored Feb 9, 2023
1 parent 4cf01a5 commit 213d04a
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 53 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
---
name: Publish container
name: Build & Publish container
"on":
release:
types: [published]
pull_request:
push:
branches: [main]

jobs:
push_to_registry:
name: Publish to GitHub Container Registry
publish:
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Code checkout
uses: actions/checkout@v3
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand All @@ -40,17 +30,27 @@ jobs:

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: ${{ github.event_name != 'pull_request' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@main

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
push: true
tags: |
ghcr.io/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }}
ghcr.io/${{ github.repository }}:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Create a GitHub release
uses: ncipollo/[email protected]
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
52 changes: 52 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: Build & Publish container
"on":
pull_request:

jobs:
build_and_publish:
name: Build & Publish to GitHub Container Registry
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Code checkout
uses: actions/checkout@v3

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Setup buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
13 changes: 0 additions & 13 deletions .github/workflows/release.yml

This file was deleted.

15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
FROM ruby
RUN gem install mdl
COPY . .
RUN chmod +x /entrypoint.sh
FROM ruby:3.2.0-slim
ENV MATCHERS_DIR="._actionshub_problem-matchers"
ENV MATCHER_FILE="${MATCHERS_DIR}/markdownlint.json"

COPY markdownlint.json ${MATCHER_FILE}
COPY Gemfile Gemfile.lock /
RUN bundle install \
&& mkdir -p ${MATCHERS_DIR} \
&& echo "::[add-matcher]${MATCHER_FILE}"

COPY --chmod=750 entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem 'mdl'
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GEM
remote: https://rubygems.org/
specs:
chef-utils (18.1.0)
concurrent-ruby
concurrent-ruby (1.2.0)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
mdl (0.12.0)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
mixlib-cli (~> 2.1, >= 2.1.1)
mixlib-config (>= 2.2.1, < 4)
mixlib-shellout
mixlib-cli (2.1.8)
mixlib-config (3.0.27)
tomlrb
mixlib-shellout (3.2.7)
chef-utils
rexml (3.2.5)
tomlrb (2.0.3)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
mdl

BUNDLED WITH
2.4.1
18 changes: 9 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: 'MarkdownLint mdl Action'
author: 'Jason Field'
description: 'Run mdl on your markdown files with ease'
name: "MarkdownLint mdl Action"
author: "Jason Field"
description: "Run mdl on your markdown files with ease"
inputs:
path:
description: 'Path to scan for markdown files within the directory (and nested directories), note: cannot be used with filesToIgnore input'
description: "Path to scan for markdown files within the directory (and nested directories), note: cannot be used with filesToIgnore input"
required: false
default: './'
default: "./"
filesToIgnoreRegex:
description: 'A regex of files you do not want scanned, note: cannot be used with path input'
description: "A regex of files you do not want scanned, note: cannot be used with path input"
required: false
outputs:
output: # id of output
description: 'stdout from mdl'
description: "stdout from mdl"
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: "docker://ghcr.io/actionshub/markdownlint:v3.0.0"
6 changes: 1 addition & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash

mkdir ._actionshub_problem-matchers
cp /markdownlint.json ._actionshub_problem-matchers/markdownlint.json
echo "##[add-matcher]._actionshub_problem-matchers/markdownlint.json"

# in this context a blank string is an acceptable not set
if [ -n "$INPUT_FILESTOIGNOREREGEX" ]; then
# mdl does not currently support an exclude list so we use this to have that feature
Expand All @@ -20,6 +16,6 @@ echo "$output"
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
echo "output=$output" >> $GITHUB_OUTPUT
echo "output=$output" >> "${GITHUB_OUTPUT}"

exit $exit_code

0 comments on commit 213d04a

Please sign in to comment.