Build and push docker image #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
permissions: | |
id-token: write | |
contents: write | |
checks: write | |
packages: write | |
name: Go Build | |
'on': | |
workflow_dispatch: {} | |
push: {} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' | |
- name: Set up Go | |
uses: actions/setup-go@v2 | |
with: | |
go-version: ^1.22 | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
versionSpec: 5.x | |
- id: determine_version | |
name: Determine Version | |
uses: gittools/actions/gitversion/[email protected] | |
with: | |
additionalArguments: /overrideconfig mode=Mainline | |
- name: Install Octopus Deploy CLI | |
uses: OctopusDeploy/install-octopus-cli-action@v1 | |
with: | |
version: latest | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: https://ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push latest Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: gchr.io/mcasperson/udl:latest | |
- name: Build and push versioned Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: gchr.io/mcasperson/udl:${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }} | |
- name: Install Dependencies | |
run: go get ./... | |
shell: bash | |
- name: List Dependencies | |
run: go list -u -m all > dependencies.txt | |
shell: bash | |
- name: Collect Dependencies | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Dependencies | |
path: dependencies.txt | |
- name: List Dependency Updates | |
run: go list -u -m -f "{{if .Update}}{{.}}{{end}}" all > dependencyUpdates.txt | |
shell: bash | |
- name: Collect Dependency Updates | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Dependencies Updates | |
path: dependencyUpdates.txt | |
- name: Test | |
run: | | |
go install gotest.tools/gotestsum@latest; gotestsum --junitfile results.xml -- -v ./... -covermode=count -coverprofile=coverage.out | |
go tool cover -func=coverage.out -o=coverage.out | |
shell: bash | |
- name: Go Coverage Badge | |
uses: tj-actions/coverage-badge-go@v2 | |
with: | |
filename: coverage.out | |
- if: always() | |
name: Report | |
uses: dorny/test-reporter@v1 | |
with: | |
name: Go Tests | |
path: results.xml | |
reporter: java-junit | |
fail-on-error: 'false' | |
- name: Verify Changed files | |
uses: tj-actions/verify-changed-files@v17 | |
id: verify-changed-files | |
with: | |
files: README.md | |
- name: Commit changes | |
if: steps.verify-changed-files.outputs.files_changed == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add README.md | |
git commit -m "chore: Updated coverage badge." | |
- name: Push changes | |
if: steps.verify-changed-files.outputs.files_changed == 'true' | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ github.token }} | |
branch: ${{ github.head_ref }} | |
- run: go build -o udl cmd/main.go | |
env: | |
CGO_ENABLED: 0 | |
- id: create_release | |
name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.determine_version.outputs.semVer }}+run${{ github.run_number }}-attempt${{ github.run_attempt }} | |
release_name: Release ${{ steps.determine_version.outputs.semVer }} Run ${{ github.run_number }} Attempt ${{ github.run_attempt }} | |
draft: 'false' | |
prerelease: 'false' | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: udl | |
asset_name: udl | |
asset_content_type: application/octet-stream |