Skip to content

Commit ac6379b

Browse files
authored
Merge pull request #38 from maykinmedia/feature/extract-and-polish-reusable-actions
Extract and polish reusable actions
2 parents 980d3cc + 6bddd7f commit ac6379b

File tree

8 files changed

+52
-49
lines changed

8 files changed

+52
-49
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ jobs:
115115
make SPHINXOPTS="-W" html
116116
make linkcheck
117117
working-directory: docs
118+
env:
119+
FORCE_COLOR: "1"
118120

119121
docker-build:
120122
runs-on: ubuntu-latest
@@ -124,26 +126,15 @@ jobs:
124126
- uses: actions/checkout@v4
125127
- name: Determine tag/commit hash
126128
id: vars
127-
run: |
128-
# Strip git ref prefix from version
129-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
130-
131-
# Strip "v" prefix from tag name (if present at all)
132-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
133-
134-
# Use Docker `latest` tag convention
135-
[ "$VERSION" == "${{ inputs.main-branch }}" ] && VERSION=latest
136-
137-
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
138-
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
129+
uses: maykinmedia/open-api-workflows/actions/extract-version@feature/extract-and-polish-reusable-actions
139130
- name: Build the Docker image
140131
run: |
141132
docker build \
142-
--tag ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.tag }} \
133+
--tag ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.version }} \
143134
--build-arg COMMIT_HASH=${{ steps.vars.outputs.git_hash }} \
144-
--build-arg RELEASE=${{ steps.vars.outputs.tag }} \
135+
--build-arg RELEASE=${{ steps.vars.outputs.version }} \
145136
.
146-
- run: docker image save -o image.tar ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.tag }}
137+
- run: docker image save -o image.tar ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.version }}
147138
- name: Store image artifact
148139
uses: actions/upload-artifact@v4
149140
with:

.github/workflows/publish.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,7 @@ jobs:
3939

4040
- name: Determine tag/commit hash
4141
id: vars
42-
run: |
43-
# Strip git ref prefix from version
44-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
45-
46-
# Use Docker `latest` tag convention for the default branch
47-
[[ "${{ github.event.repository.default_branch }}" == $VERSION ]] && VERSION=latest
48-
49-
# Strip "v" prefix from tag name (if present at all)
50-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
51-
52-
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
42+
uses: maykinmedia/open-api-workflows/actions/extract-version@feature/extract-and-polish-reusable-actions
5343

5444
- name: Load image
5545
run: |
@@ -59,13 +49,13 @@ jobs:
5949
run: echo "${{ secrets.docker-token }}" | docker login -u ${{ secrets.docker-username }} --password-stdin
6050

6151
- name: Push the Docker image
62-
run: docker push ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.tag }}
52+
run: docker push ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.version }}
6353

6454
- name: Push stable tag
6555
if: >
6656
startsWith(github.ref, 'refs/tags/') &&
6757
matches(github.ref, '^refs/tags/v?[0-9]+\\.[0-9]+(\\.[0-9]+)?$')
6858
run: |
69-
docker tag ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.tag }} \
59+
docker tag ${{ inputs.docker-image-name }}:${{ steps.vars.outputs.version }} \
7060
${{ inputs.docker-image-name }}:stable
7161
docker push ${{ inputs.docker-image-name }}:stable

actions/extract-version/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
version: ${{ steps.vars.outputs.version }}
1818
git_hash: ${{ steps.vars.outputs.git_hash }}
1919
steps:
20-
- uses: maykinmedia/open-api-workflows/actions/extract-version@refactor/reusable-actions
20+
- uses: maykinmedia/open-api-workflows/actions/extract-version@v6
2121
id: vars
2222
```

actions/extract-version/action.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,7 @@ runs:
3434
- name: Extract version information
3535
id: vars
3636
run: |
37-
# Strip git ref prefix from version
38-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
39-
40-
# Strip "v" prefix from tag name (if present at all)
41-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
42-
43-
# Use Docker `latest` tag convention
44-
[ "$VERSION" == "${{ github.event.repository.default_branch }}" ] && VERSION=latest
45-
46-
# PRs result in version 'merge' -> transform that into 'latest'
47-
[ "$VERSION" == "merge" ] && VERSION=latest
48-
49-
echo "version=${VERSION}" >> $GITHUB_OUTPUT
50-
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
37+
${{ github.action_path }}/extract_version.sh \
38+
"${{ github.ref }}" \
39+
"${{ github.event.repository.default_branch }}"
5140
shell: bash
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
#
3+
# Parses the github ref and extracts the version from the git tag if present, otherwise
4+
# falls back to 'latest'.
5+
#
6+
# Writes the `version` and `git_hash` output variables.
7+
#
8+
# Usage:
9+
#
10+
# ./extract_version.sh <git-ref> [<default-branch>]
11+
#
12+
# Expects the `$GITHUB_SHA` envvar to be present.
13+
14+
set -euo pipefail
15+
16+
# Initialize vars from arguments
17+
ref=$1
18+
default_branch=${2:-main}
19+
20+
# Strip git ref prefix from version
21+
VERSION=$(echo "$ref" | sed -e 's,.*/\(.*\),\1,')
22+
23+
# Strip "v" prefix from tag name (if present at all)
24+
[[ "$ref" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
25+
26+
# Use Docker `latest` tag convention
27+
[ "$VERSION" == "$default_branch" ] && VERSION=latest
28+
29+
# PRs result in version 'merge' -> transform that into 'latest'
30+
[ "$VERSION" == "merge" ] && VERSION=latest
31+
32+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
33+
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT

actions/oas-lint/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
schema-path: ${{ steps.generate.outputs.schema-path }}
1818

1919
steps:
20-
- uses: maykinmedia/open-api-workflows/actions/oas-generate@refactor/reusable-actions
20+
- uses: maykinmedia/open-api-workflows/actions/oas-generate@v6
2121
id: generate
2222
with:
2323
artifact-name: my-project-oas
@@ -32,7 +32,7 @@ jobs:
3232
uses: actions/download-artifact@v4
3333
with:
3434
name: my-project-oas
35-
- uses: maykinmedia/open-api-workflows/actions/oas-lint@refactor/reusable-actions
35+
- uses: maykinmedia/open-api-workflows/actions/oas-lint@v6
3636
with:
3737
schema-path: ${{ needs.generate.outputs.schema-path }}
3838
node-version-file: '.nvmrc'

actions/oas-sdks/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
schema-path: ${{ steps.generate.outputs.schema-path }}
1717

1818
steps:
19-
- uses: maykinmedia/open-api-workflows/actions/oas-generate@refactor/reusable-actions
19+
- uses: maykinmedia/open-api-workflows/actions/oas-generate@v6
2020
id: generate
2121
with:
2222
artifact-name: my-project-oas
@@ -31,7 +31,7 @@ jobs:
3131
uses: actions/download-artifact@v4
3232
with:
3333
name: my-project-oas
34-
- uses: maykinmedia/open-api-workflows/actions/oas-sdks@refactor/reusable-actions
34+
- uses: maykinmedia/open-api-workflows/actions/oas-sdks@v6
3535
with:
3636
schema-path: ${{ needs.generate.outputs.schema-path }}
3737
node-version-file: '.nvmrc'

actions/oas-to-postman/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
schema-path: ${{ steps.generate.outputs.schema-path }}
1616

1717
steps:
18-
- uses: maykinmedia/open-api-workflows/actions/oas-generate@refactor/reusable-actions
18+
- uses: maykinmedia/open-api-workflows/actions/oas-generate@v6
1919
id: generate
2020
with:
2121
artifact-name: my-project-oas
@@ -30,7 +30,7 @@ jobs:
3030
uses: actions/download-artifact@v4
3131
with:
3232
name: my-project-oas
33-
- uses: maykinmedia/open-api-workflows/actions/oas-to-postman@refactor/reusable-actions
33+
- uses: maykinmedia/open-api-workflows/actions/oas-to-postman@v6
3434
with:
3535
schema-path: ${{ needs.generate.outputs.schema-path }}
3636
node-version-file: '.nvmrc'

0 commit comments

Comments
 (0)