Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 520b959

Browse files
committed
Initial commit
1 parent 7d28098 commit 520b959

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Docker Publish
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
tag:
7+
description: "The tag for the Docker image, e.g., 'latest' or 'main'"
8+
required: true
9+
type: string
10+
platforms:
11+
description: "The platforms for Docker image build, e.g., 'linux/amd64,linux/arm64'"
12+
required: true
13+
type: string
14+
secrets:
15+
DOCKERHUB_USERNAME:
16+
required: true
17+
DOCKERHUB_TOKEN:
18+
required: true
19+
20+
jobs:
21+
publish:
22+
environment: release-docker
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@main
28+
with:
29+
show-progress: false
30+
submodules: recursive
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@master
34+
35+
- name: Login to ghcr.io
36+
uses: docker/login-action@master
37+
with:
38+
registry: ghcr.io
39+
username: ${{ github.repository_owner }}
40+
password: ${{ secrets.GITHUB_TOKEN }}
41+
42+
- name: Login to DockerHub
43+
uses: docker/login-action@master
44+
with:
45+
username: ${{ secrets.DOCKERHUB_USERNAME }}
46+
password: ${{ secrets.DOCKERHUB_TOKEN }}
47+
48+
- name: Prepare environment outputs
49+
shell: sh
50+
run: |
51+
set -eu
52+
53+
echo "DATE_ISO8601=$(date --iso-8601=seconds --utc)" >> "$GITHUB_ENV"
54+
echo "GHCR_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
55+
echo "DH_REPOSITORY=$(echo ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
56+
if [ "${{ inputs.tag }}" != "main" ]; then
57+
echo "FIXED_TAG=$(echo ${{ github.ref }} | cut -d '/' -f 3)" >> "$GITHUB_ENV"
58+
fi
59+
60+
- name: Build and publish Docker image from Dockerfile
61+
uses: docker/build-push-action@master
62+
with:
63+
context: .
64+
platforms: ${{ inputs.platforms }}
65+
provenance: true
66+
sbom: true
67+
push: true
68+
labels: |
69+
org.opencontainers.image.created=${{ env.DATE_ISO8601 }}
70+
org.opencontainers.image.version=${{ inputs.tag == 'main' && github.sha || env.FIXED_TAG }}
71+
org.opencontainers.image.revision=${{ github.sha }}
72+
tags: |
73+
ghcr.io/${{ env.GHCR_REPOSITORY }}:${{ inputs.tag }}
74+
${{ env.DH_REPOSITORY }}:${{ inputs.tag }}
75+
${{ inputs.tag != 'main' && format('ghcr.io/{0}:{1}', env.GHCR_REPOSITORY, env.FIXED_TAG) || '' }}
76+
${{ inputs.tag != 'main' && format('{0}:{1}', env.DH_REPOSITORY, env.FIXED_TAG) || '' }}
77+
78+
- name: Update DockerHub repository description
79+
if: ${{ inputs.tag == 'main' }}
80+
uses: peter-evans/dockerhub-description@main
81+
with:
82+
username: ${{ secrets.DOCKERHUB_USERNAME }}
83+
password: ${{ secrets.DOCKERHUB_TOKEN }}
84+
repository: ${{ env.DH_REPOSITORY }}
85+
short-description: ${{ github.event.repository.description }}

.github/workflows/keep-alive.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: keep-alive
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
heartbeat:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
actions: write
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@main
16+
17+
- name: Keep workflow alive
18+
uses: gautamkrishnar/keepalive-workflow@version2

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
# github-workflows
1+
# GitHub Workflows
2+
3+
This repository serves as the base for my reusable GitHub Actions workflows, streamlining the integration and consumption of public actions across my projects.

0 commit comments

Comments
 (0)