Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve actions #22

Merged
merged 10 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name-template: 'Release v$NEXT_PATCH_VERSION'
tag-template: 'v$NEXT_PATCH_VERSION'
categories:
- title: '🚀 Features'
label: 'feature'
- title: '🐛 Bug Fixes'
label: 'bug'
- title: '🧰 Maintenance'
label: 'maintenance'
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
exclude-labels:
- 'skip-changelog'
template: |
## What’s Changed

$CHANGES

**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$NEXT_PATCH_VERSION

## Docker Image
The Docker image for this release can be pulled using the following command:
```bash
docker pull {{IMAGE_TAG}}
```
56 changes: 30 additions & 26 deletions .github/workflows/create_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ jobs:
with:
fetch-depth: 0

- name: Tag and prepare release
id: tag_and_prepare_release
uses: K-Phoen/semver-release-action@master
with:
release_branch: main
env:
GITHUB_TOKEN: ${{ secrets.WF_TOKEN }}

- name: Upload release notes
if: steps.tag_and_prepare_release.outputs.tag
uses: Roang-zero1/github-create-release-action@v3
with:
created_tag: ${{ steps.tag_and_prepare_release.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.WF_TOKEN }}

- name: Login to Container registry
uses: docker/login-action@v3
with:
Expand All @@ -55,25 +39,45 @@ jobs:
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}

- name: Build variables
id: build_var
id: build_env
run: |
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
echo "PROJECT_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
echo "PROJECT_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" >> $GITHUB_ENV
echo "VCS_REF=$GITHUB_SHA" >> $GITHUB_OUTPUT

- name: Generate tag
id: generate_tag
uses: K-Phoen/semver-release-action@master
with:
release_branch: main
release_strategy: none
env:
GITHUB_TOKEN: ${{ secrets.WF_TOKEN }}


- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: |
VERSION=${{ steps.build_var.outputs.SOURCE_TAG }}
VCS_REF=${{ steps.build_var.outputs.VCS_REF }}
BUILD_DATE=${{ steps.build_var.outputs.BUILD_DATE }}
PROJECT_URL=${{ steps.build_var.outputs.PROJECT_URL }}
VERSION=${{ steps.generate_tag.outputs.tag }}
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
PROJECT_URL=${{ env.PROJECT_URL }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Push tag
env:
GITHUB_TOKEN: ${{ secrets.WF_TOKEN }}
run: |
git tag ${{ steps.generate_tag.outputs.tag }}
git push origin --tags

78 changes: 0 additions & 78 deletions .github/workflows/release.yaml

This file was deleted.

37 changes: 26 additions & 11 deletions .github/workflows/release_tags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
contents: write
packages: write
pull-requests: write
attestations: write
steps:
- name: Checkout
Expand All @@ -40,13 +41,11 @@ jobs:
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}

- name: Build variables
id: build_var
id: build_env
run: |
echo "SOURCE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "SOURCE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
echo "PROJECT_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" >> $GITHUB_OUTPUT
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
echo "PROJECT_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" >> $GITHUB_ENV
echo "VCS_REF=$GITHUB_SHA" >> $GITHUB_OUTPUT

- name: Build and push Docker image
Expand All @@ -56,16 +55,32 @@ jobs:
context: .
push: true
build-args: |
VERSION=${{ steps.build_var.outputs.SOURCE_TAG }}
VCS_REF=${{ steps.build_var.outputs.VCS_REF }}
BUILD_DATE=${{ steps.build_var.outputs.BUILD_DATE }}
PROJECT_URL=${{ steps.build_var.outputs.PROJECT_URL }}
VERSION=${{ env.SOURCE_TAG }}
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
PROJECT_URL=${{ env.PROJECT_URL }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Use Docker Image URL in Release Drafter
env:
IMAGE_TAG: ${{ steps.meta.outputs.tags }}
run: |
sed -i "s|{{IMAGE_TAG}}|${IMAGE_TAG}|g" .github/release-drafter.yml

- name: Run Release Drafter
id: create_release
uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter.yml
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Generate artifact attestation
# uses: actions/attest-build-provenance@v1
# with:
# subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
# subject-digest: ${{ steps.push.outputs.digest }}
# push-to-registry: true

94 changes: 71 additions & 23 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,82 @@
name: Test and coverage
name: Test, coverage and build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: w6d-io/process-rest

jobs:
check:
tests:
runs-on: ubuntu-latest
permissions:
contents: write
checks: write
actions: write
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Test
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...

- name: Build
run: go build -v ./...

- name: coverage
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: false # optional (default = false)
verbose: false # optional (default = false)
- name: Git Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Test
run: go test -v -coverprofile=coverage.txt -covermode=atomic ./...

- name: Build
run: go build -v ./...

- name: coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)

docker-build:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4
- name: Login to Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=pr
- name: Build variables
id: build_env
run: |
echo "SOURCE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
echo "PROJECT_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" >> $GITHUB_ENV
echo "VCS_REF=$GITHUB_SHA" >> $GITHUB_OUTPUT

- name: Build Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: false
build-args: |
VERSION=${{ env.SOURCE_TAG }}
VCS_REF=${{ env.VCS_REF }}
BUILD_DATE=${{ env.BUILD_DATE }}
PROJECT_URL=${{ env.PROJECT_URL }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ LABEL maintainer="${USER_NAME} <${USER_EMAIL}>" \
io.w6d.version=$VERSION
RUN curl -sSL https://git.io/get-mo -o mo && \
chmod +x mo && \
mv mo /usr/local/bin/ && \
apt update && apt install -y postgresql-client && \
rm -rf /var/lib/apt/lists/*
mv mo /usr/local/bin/

WORKDIR /
COPY --from=builder /github.com/w6d-io/process-rest/process-rest /usr/local/bin/process-rest
Expand Down
Loading