Created
October 22, 2024 19:59
-
-
Save xFuture603/4933f23cbe59fe9eba5fc832e84e4ada to your computer and use it in GitHub Desktop.
A example pipeline to release a package with semantic-release and build a Docker Image based on the latest tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release and Build a Docker Image | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
actions: write | |
issues: write | |
pull-requests: write | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Ensure that all tags are fetched | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run Semantic Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: npx semantic-release | |
build-and-push-image: | |
needs: release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
if: success() | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Ensure that all tags are fetched | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get latest Git tag | |
id: version | |
run: | | |
# Fetch the latest tag generated by semantic-release | |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) | |
echo "Latest Git tag: $latest_tag" | |
echo "version=$latest_tag" >> $GITHUB_ENV | |
- name: Set Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
tags: | | |
type=raw,value=latest | |
type=raw,value=${{ env.version }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment