Skip to content

Commit

Permalink
refactor: repo-visibility moved to module-info; git log analysis rena…
Browse files Browse the repository at this point in the history
…med semver
  • Loading branch information
deltics committed Aug 8, 2024
1 parent b5d9c81 commit e269ddf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 59 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/.reusable.release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: .reusable release
on: push
jobs:
gitlog:
uses: ./.github/workflows/job.git-log.yml
semver:
uses: ./.github/workflows/job.git-semver.yml
secrets: inherit

tag:
if: ${{ !fromJSON(needs.gitlog.outputs.isTagged) }}
if: ${{ !fromJSON(needs.semver.outputs.isTagged) }}
needs:
- gitlog
- semver
uses:
./.github/workflows/job.create-tag.yml
with:
label: ${{ needs.gitlog.outputs.semver }}
label: ${{ needs.semver.outputs.semver }}
lightweight: true
dryRun: ${{ (github.ref != 'refs/heads/master') }}
secrets: inherit
Expand All @@ -21,9 +21,9 @@ jobs:
uses:
./.github/workflows/job.create-release.yml
needs:
- gitlog
- semver
- tag
with:
version: ${{ needs.gitlog.outputs.semver }}
version: ${{ needs.semver.outputs.semver }}
dryRun: ${{ (github.ref != 'refs/heads/master') }}
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ on:
# most recent semver tag.
outputs:
semver:
value: ${{ jobs.analysis.outputs.semver }}
value: ${{ jobs.semver.outputs.semver }}
description: "The semantic version of the HEAD commit or the next version based on conventional commits since the most recent semver tag"
isTagged:
value: ${{ jobs.analysis.outputs.isTagged }}
value: ${{ jobs.semver.outputs.isTagged }}
description: "true if the semver output is an existing tag; false if the semver output is the next version, yet to be tagged"
jobs:
analysis:
semver:
name: 'git log analysis'
runs-on: ubuntu-latest
outputs:
Expand Down
90 changes: 50 additions & 40 deletions .github/workflows/job.module-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,55 @@ on:
default: '.'
outputs:
moduleName:
value: ${{ jobs.module-info.outputs.moduleName }}
value: ${{ jobs.module.outputs.moduleName }}
goVersion:
value: ${{ jobs.module-info.outputs.goVersion }}
serviceName:
value: ${{ jobs.module-info.outputs.serviceName }}
ingressPath:
value: ${{ jobs.module-info.outputs.ingressPath }}
value: ${{ jobs.module.outputs.goVersion }}
usesGoReleaser:
value: ${{ jobs.module-info.outputs.usesGoReleaser }}
value: ${{ jobs.module.outputs.usesGoReleaser }}
isPublic:
value: ${{ jobs.module.outputs.isPublic }}

jobs:
module-info:
module:
outputs:
moduleName: ${{ steps.info.outputs.moduleName }}
goVersion: ${{ steps.info.outputs.goVersion }}
serviceName: ${{ steps.info.outputs.serviceName }}
ingressPath: ${{ steps.info.outputs.ingressPath }}
usesGoReleaser: ${{ steps.info.outputs.usesGoReleaser }}
moduleName: ${{ steps.go-mod.outputs.moduleName }}
goVersion: ${{ steps.go-mod.outputs.goVersion }}
usesGoReleaser: ${{ steps.go-releaser.outputs.configExists }}
isPublic: ${{ steps.repo.outputs.isPublic }}
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # get tags and branches for gitversion

- name: 'github: visibility'
id: repo
run: |
OUTPUT=$(curl --header "Authorization: token ${{ github.token }}" https://api.github.com/repos/${{ github.repository }})
echo "::group::api result"
echo "$OUTPUT"
echo "::endgroup::"
case $(echo $OUTPUT | jq ".private") in
false) isPublic=true
;;
true) isPublic=false
;;
*) echo "::error::unable to get repository info:$(echo $OUTPUT | jq '.message')"
exit -1
;;
esac
echo "::group::outputs"
echo "isPublic=$isPublic" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
echo "::endgroup::"
- name: 'go.mod: parse'
id: info
id: go-mod
shell: bash --noprofile --norc {0}
run: |
# a script to extract build information from ${{ inputs.path }}/go.mod
Expand Down Expand Up @@ -62,33 +84,21 @@ jobs:
# get go version from go.mod
gover=$(echo "$mod" | grep -E "^go "); gover=${gover##* }; gover=${gover%% *}
# get service name from go.mod
service=$(echo "$mod" | grep -E "^//service:name:" -m 1); service=${service##*:}
# if the service name is not explicitly set but a //service comment is
# present then use the module name as the service name (without host.tld/ prefix)
if [[ -z $service && ! -z $(echo "$mod" | grep -E "^//service[\s]*$") ]]; then
if [[ ! -z $(echo "$module" | grep "/") ]]; then service=${module##*/}; fi
if [[ -z $service ]]; then service=$module; fi
fi
service=${service%% *}
# get ingress path from go.mod
ingress=$(echo "$mod" | grep -E "^//ingress:path:" -m 1); ingress=${ingress##*:}
echo "::group::outputs"
echo "moduleName=$module" >> $GITHUB_OUTPUT
echo "goVersion=$gover" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
echo "::endgroup::"
- name: 'go releaser: config'
id: go-releaser
shell: bash --noprofile --norc {0}
run: |
# check for presence of a .goreleaser.yml|yaml file
[[ -f .goreleaser.yml || -f .goreleaser.yaml ]] && usesGoReleaser="true"
configExists="false"
[[ -f ${{ inputs.path }}/.goreleaser.yml || -f ${{ inputs.path }}/.goreleaser.yaml ]] && configExists="true"
echo "::group::results/outputs"
echo "moduleName : $module"
echo "goVersion : $gover"
echo "serviceName : $service"
echo "ingressPath : $ingress"
echo "usesGoReleaser: $usesGoReleaser"
echo "moduleName=$module" >> $GITHUB_OUTPUT
echo "goVersion=$gover" >> $GITHUB_OUTPUT
echo "serviceName=$service" >> $GITHUB_OUTPUT
echo "ingressPath=$ingress" >> $GITHUB_OUTPUT
echo "usesGoReleaser=$usesGoReleaser" >> $GITHUB_OUTPUT
echo "::group::outputs"
echo "configExists=$configExists" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
echo "::endgroup::"
20 changes: 11 additions & 9 deletions .github/workflows/job.module-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ on:
value: ${{ jobs.module-info.outputs.moduleName }}
goVersion:
value: ${{ jobs.module-info.outputs.goVersion }}
semver:
value: ${{ jobs.semver.outputs.semver }}
isTagged:
value: ${{ jobs.semver.outputs.isTagged }}
isPublic:
value: ${{ jobs.module-info.outputs.isPublic }}
usesGoReleaser:
value: ${{ jobs.module-info.outputs.usesGoReleaser }}
semver:
value: ${{ jobs.semver.outputs.semver }}
isTagged:
value: ${{ jobs.semver.outputs.isTagged }}

jobs:
semver:
Expand All @@ -32,9 +32,6 @@ jobs:
if: ${{ (github.ref != 'refs/heads/master' ) || (needs.module-info.outputs.isPublic == 'true' ) }}
needs:
- module-info
outputs:
isPublic: ${{ needs.module-info.outputs.isPublic }}
moduleName: ${{ needs.module-info.outputs.moduleName }}
runs-on: ubuntu-latest
steps:
- name: checkout
Expand All @@ -51,9 +48,14 @@ jobs:
- name: 'go.mod: tidy'
id: tidy
run: |
# a script to determine whether 'go mod tidy' is required
before=$(cat go.mod go.sum | shasum -a 256)
go mod tidy
echo "::group::go mod tidy output"
go mod tidy
echo "::endgroup::"
after=$(cat go.mod go.sum | shasum -a 256)
if [[ "$before" != "$after" ]]; then
echo "::error::'go mod tidy' is required; updated go.mod/go.sum must be committed"
exit -1
Expand All @@ -62,7 +64,7 @@ jobs:
# lint checks
- name: 'go: lint'
if: ${{ github.ref != 'refs/heads/master' }}
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: latest

Expand Down

0 comments on commit e269ddf

Please sign in to comment.