Skip to content

Commit

Permalink
cd: create new workflows #3 (#4)
Browse files Browse the repository at this point in the history
* cd: create new workflows #3

* fix: create setup .NET

* feat: create testing workflow

* fix: change dotnet version

* fix: change on PR & collectCoverage
  • Loading branch information
SantiagoGaonaC authored Sep 26, 2023
1 parent 63bec7b commit c210600
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Coverage

on:
push:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0

- name: Install dependencies
run: dotnet add package Microsoft.CodeCoverage

- name: Test
run: dotnet test --no-restore --verbosity normal /p:CollectCoverage=true

- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.cobertura.xml
74 changes: 74 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Release

on:
push:
branches: ["main"]

jobs:
versioning:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.latest_version.outputs.version }}
steps:
- uses: actions/checkout@v3
- id: latest_version
name: Latest version
run: node version.js >> $GITHUB_OUTPUT

create-release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
needs:
- versioning
outputs:
upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- name: Create Release
id: create-release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.versioning.outputs.version }}
release_name: Release ${{ needs.versioning.outputs.version }}
draft: false
prerelease: false

build-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs:
- versioning
- create-release
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Docker image
run: echo "v${{ needs.versioning.outputs.version }}"

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:latest,ghcr.io/${{ github.repository }}:${{ needs.versioning.outputs.version }}
labels: ${{ steps.meta.outputs.labels }}
28 changes: 28 additions & 0 deletions .github/workflows/tagging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tagging

on:
push:
branches: ["dev"]

jobs:
tagging:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "npm"
- name: Git Identity
run: |
git checkout dev
git fetch --all --tags
git config --global user.email "[email protected]"
git config --global user.name "Antonio Donis"
- name: Changelog
run: 'npx standard-version --message "[ci skip] chore(release): %s"'
- name: Push changes
run: git push --follow-tags --force origin dev
26 changes: 26 additions & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on:
pull_request:
branches: ["dev"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout PR branch
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0

- name: Restore dependencies
run: dotnet restore

- name: Build and Test
run: dotnet test --no-restore --verbosity normal
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"devDependencies": {
"git-semver-tags": "^4.1.1",
"standard-version": "^9.5.0"
},
"version": "0.0.0"
}
10 changes: 10 additions & 0 deletions version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const fs = require("fs");

fs.readFile("package.json", "utf8", (err, data) => {
if (err) {
console.error("Failed to read package.json:", err);
process.exit(1);
}
const pkg = JSON.parse(data);
console.log(`version=${pkg.version}`);
});

0 comments on commit c210600

Please sign in to comment.