Skip to content

Commit

Permalink
Add APP_VERSION parsing to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Jun 26, 2024
1 parent 26dab38 commit 734742e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/act/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Testing GH Actions with [ACT]

### Test Branch Push

```shell
act -W '.github/act/actTest.yml' -e '.github/act/actBranchEvent.json'
```


### Test Tag Push

```shell
act -W '.github/act/actTest.yml' -e '.github/act/actTagEvent.json'
```
4 changes: 4 additions & 0 deletions .github/act/actBranchEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"ref": "refs/heads/master",
"sha": "0a1a94d9ad4efa373f8d34aace5e7f0a3fff42ad"
}
5 changes: 5 additions & 0 deletions .github/act/actTagEvent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ref": "refs/tags/0.8.0",
"ref_name": "0.8.0",
"sha": "0a1a94d9ad4efa373f8d34aace5e7f0a3fff42ad"
}
45 changes: 45 additions & 0 deletions .github/act/actTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Docker image to Dockerhub

on:
push:
branches:
- 'master'
- 'develop'
tags:
- '*.*.*'
# don't trigger if just updating docs
paths-ignore:
- '**.md'
# use release instead of tags once version is correctly parsed
# https://github.com/docker/metadata-action/issues/422
# https://github.com/docker/metadata-action/issues/240
# release:
# types: [ published ]

jobs:

test:
name: Build and push container images
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set short git commit SHA
id: vars
# https://dev.to/hectorleiva/github-actions-and-creating-a-short-sha-hash-8b7
# short sha available under env.COMMIT_SHORT_SHA
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Check App Version
env:
# use release instead of tags once version is correctly parsed
#APP_VERSION: ${{ github.event.release.tag_name }}

# https://github.com/actions/runner/issues/409#issuecomment-752775072
# https://stackoverflow.com/a/69919067/1469797
APP_VERSION: ${{ contains(github.ref, 'refs/tags/') && github.ref_name || format('{0}-{1}', github.ref_name, env.COMMIT_SHORT_SHA ) }}
run: |
echo $APP_VERSION
20 changes: 20 additions & 0 deletions .github/workflows/publishImage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:
# don't trigger if just updating docs
paths-ignore:
- '**.md'
# use release instead of tags once version is correctly parsed
# https://github.com/docker/metadata-action/issues/422
# https://github.com/docker/metadata-action/issues/240
# release:
# types: [ published ]

jobs:
test:
Expand Down Expand Up @@ -54,6 +59,14 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4

- name: Set short git commit SHA
id: vars
# https://dev.to/hectorleiva/github-actions-and-creating-a-short-sha-hash-8b7
# short sha available under env.COMMIT_SHORT_SHA
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
Expand Down Expand Up @@ -92,6 +105,13 @@ jobs:
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
env:
# use release instead of tags once version is correctly parsed
#APP_VERSION: ${{ github.event.release.tag_name }}

# https://github.com/actions/runner/issues/409#issuecomment-752775072
# https://stackoverflow.com/a/69919067/1469797
APP_VERSION: ${{ contains(github.ref, 'refs/tags/') && github.ref_name || format('{0}-{1}', github.ref_name, env.COMMIT_SHORT_SHA ) }}
uses: docker/build-push-action@v5
with:
context: .
Expand Down

0 comments on commit 734742e

Please sign in to comment.