Skip to content

Merge branch 'main' of https://github.com/goraxe/website #15

Merge branch 'main' of https://github.com/goraxe/website

Merge branch 'main' of https://github.com/goraxe/website #15

Workflow file for this run

#
name: CD
permissions:
contents: read
# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
branches: ["main", "master"]
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Trunk Check
uses: trunk-io/trunk-action@v1
semantic-release:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.semantic.outputs.new_release_version }}
new-release-published: ${{ steps.semantic.outputs.new_release_published }}
steps:
- uses: actions/checkout@v4
# you'll need to add an `id` in order to access output variables
- uses: cycjimmy/semantic-release-action@v4
id: semantic
with:
dry_run: true
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-push-image:
needs: [semantic-release, pre-commit]
if: needs.semantic-release.outputs.new-release-published == 'true'
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: set up docker buildx
uses: docker/setup-buildx-action@v3
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
env:
TAG: v${{ needs.semantic-release.outputs.release-version }}
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.release-version}}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.release-version }}
type=semver,pattern={{major}},value=${{ needs.semantic-release.outputs.release-version }}
type=ref,event=branch
type=ref,event=pr
type=sha
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# create-deployment:
# runs-on: ubuntu-latest
# needs: [semantic-release, build-and-push-image]
# steps:
# - uses: actions/create-github-app-token@v1
# id: app-token
# with:
# app-id: ${{ vars.APP_ID }}
# private-key: ${{ secrets.PRIVATE_KEY }}
# - name: Checkout repository
# uses: actions/checkout@v4
# with:
# token: ${{ steps.app-token.outputs.token }}
# - uses: imranismail/setup-kustomize@v2
# - name: run kustomize
# continue-on-error: true
# run: |
# pushd deploy
# kustomize edit set image ghcr.io/ghcr.io/goraxe/portal=ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.semantic-release.outputs.release-version }}
# git config --local user.name "deployment bot"
# git config --local user.email "github-actions[bot]@users.noreply.github.com"
# git add .
# git commit -m "chore(release): Set image tag to `${{ needs.semantic-release.outputs.release-version }}` [skip ci]"
# git push
# popd
semantic-release-final:
needs:
- build-and-push-image
runs-on: ubuntu-latest
outputs:
release-version: ${{ steps.semantic.outputs.release-version }}
new-release-published: ${{ steps.semantic.outputs.new-release-published }}
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
# you'll need to add an `id` in order to access output variables
- uses: cycjimmy/semantic-release-action@v4
id: semantic
with:
extra_plugins: |
@semantic-release/changelog
@semantic-release/git
@semantic-release/exec
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}