diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 642fc29..c988f76 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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/github-tag-action@v6.1 + 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 @@ -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/release-action@v1.12.0 + with: + tag: ${{ steps.tag_version.outputs.new_tag }} + name: Release ${{ steps.tag_version.outputs.new_tag }} + body: ${{ steps.tag_version.outputs.changelog }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 0000000..03bca3f --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -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 }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index ddf7cd5..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,13 +0,0 @@ -name: release -on: - push: - branches: [main] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Bump version and push tag - uses: mathieudutour/github-tag-action@v5 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile b/Dockerfile index 323d8ca..14dd225 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4834540 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'mdl' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d906025 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/action.yml b/action.yml index e34f4f2..5a86958 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/entrypoint.sh b/entrypoint.sh index 5a6bef3..f987d84 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -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