Skip to content

Commit

Permalink
fix: imporvements to workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jodevsa committed May 12, 2023
1 parent 1356019 commit 9ccdfa3
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ env:
TARGET_PLATFORMS: linux/amd64,linux/arm64
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

on:
pull_request: {}
push:
tags:
- 'v*'
branches:
- 'main'
workflow_call:
inputs:
ref:
required: true
type: string
new_images_tag:
required: true
type: string
set_new_images_as_latest:
required: true
type: boolean



permissions:
contents: read
Expand All @@ -29,6 +37,7 @@ jobs:
- uses: actions/checkout@v3
name: Checkout repository
with:
ref: ${{ inputs.ref }}
submodules: true

- name: Set up QEMU
Expand All @@ -52,12 +61,8 @@ jobs:
uses: docker/metadata-action@v4
with:
tags: |
# set tag with branch name 'wireguard-images/manager:pr-3'
type=ref,event=branch
# set tag with semver. example: 'wireguard-images/manager:v1.5.3'
type=semver,pattern={{raw}}
# set latest tag for 'main' branch. example: 'wireguard-images/manager:latest'
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest, enable=${{ inputs.set_new_images_as_latest}}
type=raw,value=${{ new_images_tag }},
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.image }}

- uses: actions/setup-go@v3
Expand All @@ -70,6 +75,6 @@ jobs:
context: .
file: images/${{ matrix.image }}/Dockerfile
platforms: ${{ env.TARGET_PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
push: ${{ inputs.push }}
tags: ${{ steps.image-meta.outputs.tags }}
labels: ${{ steps.image-meta.outputs.labels }}
154 changes: 154 additions & 0 deletions .github/workflows/manual-release-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
name: DEV Release
on:
workflow_dispatch:
inputs:
repository:
description: 'Repository name with owner.'
required: true
default: 'jodevsa/wireguard-operator'
type: string
branch:
description: 'The branch, tag or SHA to checkout.'
required: true
default: 'main'
type: string
platforms:
description: 'Docker image platforms'
required: true
default: 'linux/amd64, linux/arm64'
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

permissions:
contents: read
packages: write

jobs:
build-manager:
runs-on: ubuntu-latest

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
submodules: true

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

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
tags: |
type=sha,format=long,prefix=development-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/manager

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: ./images/manager/Dockerfile
context: ./
push: true
platforms: ${{ inputs.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

outputs:
image: ${{ steps.meta.outputs.tags }}

build-agent:
runs-on: ubuntu-latest

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
with:
install: true

- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
submodules: true

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

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
tags: |
type=sha,format=long,prefix=development-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/agent

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
file: ./images/agent/Dockerfile
context: ./
push: true
platforms: ${{ inputs.platforms }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

outputs:
image: ${{ steps.meta.outputs.tags }}

save-release:
needs: [build-agent, build-manager]
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.20

- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.branch }}
submodules: true

- name: prepare new release
env:
MANAGER_IMAGE: ${{ needs.build-manager.outputs.image }}
AGENT_IMAGE: ${{ needs.build-agent.outputs.image }}
run : |
make generate-release-file AGENT_IMAGE="$AGENT_IMAGE" MANAGER_IMAGE="$MANAGER_IMAGE"
mv ./release.yaml /tmp/release.yaml
- name: upload release
uses: actions/upload-artifact@v3
with:
name: manual-release-dev.yaml
path: /tmp/manual-release-dev.yaml
32 changes: 32 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ on:
permissions: write-all

jobs:
retreive-next-release-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout repository
with:
submodules: true
- name: semantic-release extract new version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/git semantic-release/exec
echo "version=$(npx semantic-release --dryRun grep -oP 'Published release \K.*? ')" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ steps.step1.outputs.version }}

call-workflow-in-local-repo:
needs: retreive-next-release-version
uses: ./.github/workflows/build-images-workflow.yaml
with:
set_new_images_as_latest: false
push: true
new_images_tag: ${{needs.retreive-next-release-version.outputs.version}}
ref: ${{needs.retreive-next-release-version.outputs.version}}

release:
runs-on: ubuntu-latest
steps:
Expand All @@ -15,6 +40,13 @@ jobs:
with:
submodules: true

- name: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npm install @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/git semantic-release/exec
npx semantic-release
- name: semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit 9ccdfa3

Please sign in to comment.