Skip to content

Commit

Permalink
fix: Docker tag on main (#37)
Browse files Browse the repository at this point in the history
* fix: Docker tag on main
- Docker tag wasn't set correctly
- Set a pretty commit message for Actions update

Signed-off-by: Dan Webb <dan.webb@damacus.io>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
damacus and github-actions[bot] committed Feb 13, 2023
1 parent 13f22fc commit 1f70dbb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Build & Publish container
"on":
pull_request:
push:
branches: [main]

Expand All @@ -19,22 +18,6 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: Dry Run Bump version and push tag
id: dry_run_tag_version
if: github.event_name == 'pull_request'
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true

- name: Bump version and push tag
id: tag_version
if: github.ref == 'refs/heads/main'
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: false

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
Expand All @@ -56,19 +39,12 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Update actions.yml
if: github.event_name == 'pull_request'
uses: mikefarah/yq@v4.30.8
with:
cmd: yq e -i '.runs.image = "docker://ghcr.io/${{ github.repository }}:${{ steps.dry_run_tag_version.outputs.new_tag }}"' action.yml

- name: Commit Changes to actions.yml
if: github.event_name == 'pull_request'
uses: EndBug/add-and-commit@v9
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
message: "Update actions.yml"
add: "action.yml"
default_author: github_actions
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: false

- name: Build and push
uses: docker/build-push-action@v4
Expand All @@ -78,11 +54,10 @@ jobs:
push: true
tags: |
${{ steps.meta.outputs.tags }}
${{ steps.tag_version.outputs.new_tag }}
ghcr.io/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }}
labels: ${{ steps.meta.outputs.labels }}

- name: Create a GitHub release
if: github.ref == 'refs/heads/main'
uses: ncipollo/release-action@v1.12.0
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: Build & Publish container
"on":
pull_request:

jobs:
build_and_publish:
name: Build & Publish to GitHub Container Registry
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Code checkout
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}

- 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: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
dry_run: true

- name: Update actions.yml to ${{ steps.tag_version.outputs.new_tag }}
uses: mikefarah/yq@v4.30.8
with:
cmd: yq e -i '.runs.image = "docker://ghcr.io/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }}"' action.yml

- name: Commit Changes to actions.yml
uses: EndBug/add-and-commit@v9
with:
message: "Update actions.yml to ${{ steps.tag_version.outputs.new_tag }}"
add: "action.yml"
default_author: github_actions

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.meta.outputs.tags }}
ghcr.io/${{ github.repository }}:${{ steps.tag_version.outputs.new_tag }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ outputs:
description: "stdout from mdl"
runs:
using: "docker"
image: "docker://ghcr.io/actionshub/markdownlint:v3.1.1"
image: "docker://ghcr.io/actionshub/markdownlint:v3.1.2"

0 comments on commit 1f70dbb

Please sign in to comment.