Skip to content

Merge pull request #177 from go-faster/dependabot/go_modules/go.opent… #131

Merge pull request #177 from go-faster/dependabot/go_modules/go.opent…

Merge pull request #177 from go-faster/dependabot/go_modules/go.opent… #131

Workflow file for this run

name: release
on:
push:
branches: [main]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
KUBECTL_VER: v1.27.1
K8S_NS: faster
jobs:
deploy:
environment: prod
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
KUBECONFIG: /tmp/kubeconfig
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
cache: false
- name: Get Go environment
id: go-env
run: |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
uses: actions/cache@v4
with:
path: |
${{ env.cache }}
${{ env.modcache }}
key: release-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
release-${{ runner.os }}-go-
- name: Docker log in
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Image metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=edge,branch=main
type=sha
- name: Go build
env:
CGO_ENABLED: 0
run: go build -v ./cmd/gh-archived
- name: Image build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Get short commit SHA
id: var
shell: bash
run: |
echo "::set-output name=sha::$(git rev-parse --short HEAD)"
- name: Generate deployment with SHA version
run: sed 's/:main/:sha-${{ steps.var.outputs.sha }}/g' .k8s/deployment.yml > .k8s/deployment.release.yml
- name: Set up kubectl cache
uses: actions/cache@v4
with:
path: /usr/local/bin/kubectl
key: kubectl-${{ env.KUBECTL_VER }}
- name: Check kubectl
id: "kubectl"
uses: andstor/file-existence-action@v3
with:
files: /usr/local/bin/kubectl
- name: Download kubectl
if: steps.kubectl.outputs.files_exists != 'true'
run: |
wget -O /usr/local/bin/kubectl "https://dl.k8s.io/release/${{ env.KUBECTL_VER }}/bin/linux/amd64/kubectl"
chmod +x /usr/local/bin/kubectl
- name: Setup kubeconfig
env:
KUBE: ${{ secrets.KUBE }}
run: .k8s/kubeconfig.sh
- name: Deploy
run: |
kubectl apply -f .k8s/deployment.release.yml
kubectl -n ${{ env.K8S_NS }} rollout status deployment/gh-archived