Skip to content

Commit

Permalink
ci: automated versioning and publishing (#181)
Browse files Browse the repository at this point in the history
> [!IMPORTANT]  
> **This change impacts how pull requests should be titled and merged**.
See below for details.

This changeset looks to resolve the issue that we have seen crop up over
the past few weeks where changes have been merged into `master` but
because a bunch of manual steps haven't been completed, new releases
(docker images) haven't been published.

For the workflows in this pull request to work correctly, one new
variable and two new secrets need to be created:

| Type | Name | Notes |
| ------------------ | ------------------ | ------------------ |
| Variable | DOCKERHUB_USERNAME | The username/account of the Docker Hub
profile under which images built should be published. |
| Secret | DOCKERHUB_TOKEN | The [access
token](https://docs.docker.com/security/for-developers/access-tokens/)
to be used to authenticate to Docker Hub. |
| Secret | GH_ACCESS_TOKEN | The GitHub access token to be used. This is
required because GitHub blocks commits created by actions spawning other
actions when using the default workflow token. |

The secrets and variable can be created from within the repository
*Settings > Secrets and variables -> Actions*.

## Pull Requests

This change introduces a dependency on [conventional commit
messages](https://kapeli.com/cheat_sheets/Conventional_Commits.docset/Contents/Resources/Documents/index#:~:text=Commits%20MUST%20be%20prefixed%20with%20a%20type%2C%20which,commit%20represents%20a%20bug%20fix%20for%20your%20application).
The action within the versioning workflow looks at the format of the
commit message to determine which of the *major*, *minor*, or *patch*
numbers to increment.

Setting pull request titles to be in conventional commit format (like
this one) and with the below pull request settings configured will
ensure that the versioning works as expected:


![image](https://github.com/user-attachments/assets/238927ca-be57-472f-8443-26d0c174217e)

Reviewers of PRs for the project should ensure that pull request titles
are appropriate for the changes included.

Closes #147, Closes #180

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
cj13579 and github-actions[bot] authored Jan 24, 2025
1 parent 0b590ff commit aff842e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish image
on:
push:
tags:
- '*'

jobs:
publish-app:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata for the Docker image
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ vars.DOCKERHUB_USERNAME }}/christmas-community
context: git
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
29 changes: 29 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Bump version
on:
push:
branches:
- master
paths-ignore:
- 'package.json'
- 'README.md'

jobs:
version-app:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN_ACTION }}

- name: Bump version and push tag
id: changelog
uses: TriPSs/conventional-changelog-action@v6
with:
github-token: "${{ secrets.GH_TOKEN_ACTION }}"
git-user-name: "github-actions[bot]"
git-user-email: "github-actions[bot]@users.noreply.github.com"
preset: "conventionalcommits"
output-file: false
# skip-on-empty: false # good for testing
skip-ci: false
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<table>
<tr>
<td align="center">
<a href="https://github.com/Wingysam">
<img src="https://avatars.githubusercontent.com/u/18403742?v=4" width="100;" alt="Wingysam"/>
<a href="https://github.com/cj13579">
<img src="https://avatars.githubusercontent.com/u/1965454?v=4" width="100;" alt="cj13579"/>
<br />
<sub><b>Wingysam</b></sub>
<sub><b>cj13579</b></sub>
</a>
</td></tr>
</table>
Expand Down Expand Up @@ -327,6 +327,13 @@ Hi, I'm Wingy. I made this app. My website is [samwing.dev](https://samwing.dev)
<sub><b>StS82</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/alyoro">
<img src="https://avatars.githubusercontent.com/u/43644634?v=4" width="100;" alt="alyoro"/>
<br />
<sub><b>alyoro</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/toastie89">
<img src="https://avatars.githubusercontent.com/u/19393929?v=4" width="100;" alt="toastie89"/>
Expand Down

0 comments on commit aff842e

Please sign in to comment.