+
Skip to content

Refactor to new version and allow manual builds #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/actions/docker-tag-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Docker tag action'
description: "GitHub Action to create Docker tag based on branch or tag"
author: 'cytopia'
branding:
icon: 'code'
color: 'red'

inputs:
latest_git_branch:
description: 'Git branch name which will return "latest" as the Docker tag (default: master).'
required: false
default: ${{ github.event.repository.default_branch }}
latest_docker_tag_name:
description: 'The name for the "latest" Docker tag (default: latest).'
required: false
default: 'latest'
non_latest_docker_tag_prefix:
description: 'The prefix for all Docker tags, which do not identify as the conventional latest Tag (default: empty)'
required: false
default: ''
non_latest_docker_tag_suffix:
description: 'The suffix for all Docker tags, which do not identify as the conventional latest Tag (default: empty)'
required: false
default: ''

outputs:
docker-tag:
description: "Docker tag to be used"
value: ${{ steps.get-docker-tag.outputs.docker-tag }}

runs:
using: "composite"
steps:
- name: Get Docker Tag
id: get-docker-tag
shell: bash
run: |
# Commit, Branch or Tag
HEAD="$( git branch --no-color | grep '^\*' | sed 's|)||g' | xargs -n1 | tail -1 )"

# Get current Commit Hash (short)
HASH="$( git rev-parse --short HEAD )"

# Hash is found in what Branch?
FROM="$( git branch --contains "${HASH}" | head -2 | tac | head -1 | sed 's|^*[[:space:]]*||g' | sed 's|)||g' | xargs -n1 | tail -1 | xargs )"

# How many commits behind FROM branch
BEHIND="$( git rev-list --count "${HASH}..${FROM}" )"

###
### TAG
###
if git name-rev "${HEAD}" | grep -E "^${HEAD} tags/${HEAD}" > /dev/null; then
GIT_NAME="${HEAD}"
GIT_TYPE="TAG"
GIT_HEAD="${HASH}"
DETACHED_FROM=${FROM}"
BEHIND=${BEHIND}"
###
### Branch or Detached Commit
###
else
# Detached Commit (not latest in branch)
if [ "${BEHIND}" -gt "0" ]; then
GIT_NAME="${HEAD}"
GIT_TYPE="COMMIT"
GIT_HEAD="${HASH}"
DETACHED_FROM="${FROM}"
BEHIND="${BEHIND}"
else
if [ "$( git branch | grep '^\*' | sed 's|^*[[:space:]]*||g' | xargs )" = "${FROM}" ]; then
DETACHED=
else
DETACHED="${FROM}"
fi
GIT_NAME="${FROM}"
GIT_TYPE="BRANCH"
GIT_HEAD="${HASH}"
DETACHED_FROM="${DETACHED}"
BEHIND="${BEHIND}"
fi
fi

###
### Determine Docker tag
###
if [ "${GIT_TYPE}" = "BRANCH" ] && [ "${GIT_NAME}" = "${{ inputs.latest_git_branch }}" ]; then
DOCKER_TAG="${{ inputs.latest_docker_tag_name }}"
else
DOCKER_TAG="${{ inputs.non_latest_docker_tag_prefix }}${GIT_NAME}${{ inputs.non_latest_docker_tag_suffix }}"
fi

###
### Replace slashes '/' with dashes '-'
###
DOCKER_TAG="${DOCKER_TAG//\//-}"

###
### Set final output for 'docker-tag'
###
echo "docker-tag=${DOCKER_TAG}" >> $GITHUB_OUTPUT

###
### Output information
###
echo "DOCKER_TAG=${DOCKER_TAG}"
echo "GIT_NAME=${GIT_NAME}"
echo "GIT_TYPE=${GIT_TYPE}"
echo "GIT_HEAD=${GIT_HEAD}"
echo "DETACHED_FROM=${DETACHED_FROM}"
echo "BEHIND=${BEHIND}"
64 changes: 64 additions & 0 deletions .github/actions/download-artifact-retry-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'download-artifact-retry'
description: "GitHub Action to download an artifact with retry functionality."
author: 'cytopia'
branding:
icon: 'code'
color: 'red'

inputs:
name:
description: 'The artifact name to download.'
required: true
path:
description: 'The local path to download to (defaults to current working directory).'
required: false
default: '.'

runs:
using: "composite"
steps:

- name: download artifact (try-1)
id: download-1
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}

- name: download artifact (try-2)
id: download-2
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
if: ${{ steps.download-1.outcome == 'failure' }}

- name: download artifact (try-3)
id: download-3
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
if: ${{ steps.download-2.outcome == 'failure' }}

- name: download artifact (try-4)
id: download-4
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
if: ${{ steps.download-3.outcome == 'failure' }}

- name: download artifact (try-5)
id: download-5
uses: actions/download-artifact@v4
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
if: ${{ steps.download-4.outcome == 'failure' }}
141 changes: 141 additions & 0 deletions .github/actions/git-ref-matrix-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Git ref matrix action'
description: "GitHub Action to create a stringified build matrix for branches and tags."
author: 'cytopia'
branding:
icon: 'code'
color: 'red'

inputs:
repository_default_branch:
description: 'The default branch of this repository to fetch latest tags from. Default: master'
required: false
default: ${{ github.event.repository.default_branch }}
branches:
description: 'Comma separated list of branches to create build matrix for. Default: none'
required: false
default: ''
tags:
description: 'Comma separated list of tags to create build matrix for. Default: none'
required: false
default: ''
num_latest_tags:
description: 'Number of latest tags to add to build matrix. Default: 0'
required: false
default: '0'
disable_refs:
description: 'A string flag (0 or 1 or false or true) to disable refs alltogether and return an empty matrix and has_refs=false.'
required: false
default: 'false'

outputs:
matrix:
description: "(string) Stringified JSON build matrix for defined git refs. (list of strings)"
value: ${{ steps.set-matrix.outputs.matrix }}
has_refs:
description: "(string) String flag ('true' or 'false') that tells if we have matrix (list not empty) refs or not (list empty)."
value: ${{ steps.set-matrix.outputs.has_refs }}

runs:
using: "composite"
steps:

- name: "[SETUP] Checkout repository's default branch"
uses: actions/checkout@v4
with:
ref: ${{ inputs.repository_default_branch }}
fetch-depth: 0
path: .git-ref-matrix-action
if: ${{ (!inputs.disable_refs || inputs.disable_refs == 0 || inputs.disable_refs == '0' || inputs.disable_refs == 'false') && inputs.num_latest_tags > 0 }}

- name: "[SETUP] Build and Export Matrix"
id: set-matrix
shell: bash
run: |
if [ "${{ inputs.disable_refs }}" = "1" ] || [ "${{ inputs.disable_refs }}" = "true" ]; then
###
### Output matrix
###
echo "matrix=[]" >> $GITHUB_OUTPUT
echo "has_refs=false" >> $GITHUB_OUTPUT
echo "matrix=[]"
echo "has_refs=false"
else
###
### Convert comma separated branches and tags to newline separated
###
BRANCHES="$( echo "${{ inputs.branches }}" | sed 's/,/\n/g' )"
TAGS="$( echo "${{ inputs.tags }}" | sed 's/,/\n/g' )"

echo "BRANCHES:"
echo "-------------------------"
echo "${BRANCHES}"
echo

echo "TAGS:"
echo "-------------------------"
echo "${TAGS}"
echo

###
### Get x number of latest tags of this repository (newline separated)
###
if [ "${{ inputs.num_latest_tags }}" != "0" ]; then
LATEST_TAGS="$( cd .git-ref-matrix-action && git tag --sort=creatordate | tail -${{ inputs.num_latest_tags }} )"
rm -r .git-ref-matrix-action
else
LATEST_TAGS=''
fi

echo "LATEST_TAGS:"
echo "-------------------------"
echo "${LATEST_TAGS}"
echo

###
### All newline separated refs (and make unique in case of duplicated tags)
###
REFS="$( printf "%s\n%s\n%s\n" "${BRANCHES}" "${TAGS}" "${LATEST_TAGS}" | grep -Ev '^$' || true | sort -u )"

echo "REFS:"
echo "-------------------------"
echo "${REFS}"
echo

###
### Create element double-quoted and comma separated string (has leading comma)
###
JSON=''
while IFS= read -r line; do
if [ -n "${line}" ]; then
JSON="${JSON},$( printf '"%s"' "${line}" )"
fi
done <<< "${REFS}"

###
### Remove leading comma and encapsulate in square brackets
###
JSON="$( printf '[%s]' "${JSON#,}" )"

###
### Set final output for 'matrix'
###
echo "matrix=${JSON}" >> $GITHUB_OUTPUT

###
### Set 'has_refs'
###
if [ "${JSON}" = "[]" ]; then
HAS_REFS="false"
else
HAS_REFS="true"
fi
echo "has_refs=${HAS_REFS}" >> $GITHUB_OUTPUT

###
### Output matrix
###
echo "matrix=${JSON}"
echo "has_refs=${HAS_REFS}"
fi
63 changes: 63 additions & 0 deletions .github/actions/shell-command-retry-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# https://help.github.com/en/articles/metadata-syntax-for-github-actions
name: 'Shell command retry action'
description: "GitHub Action to repeatedly retry a shell command upon failure."
author: 'cytopia'
branding:
icon: 'code'
color: 'red'

inputs:
retries:
description: 'How many times to retry on failure'
required: false
default: '10'
pause:
description: 'How many seconds to wait between retries'
required: false
default: '10'
command:
description: 'Shell command to execute'
required: true
default: 'true'
fail_command:
description: 'Shell command to execute on every failure of given command (The fail_command will always succeed via: || true)'
required: false
default: ''
workdir:
description: 'Switch to this working directory prior executing shell command'
required: false
default: ''

runs:
using: "composite"
steps:
- name: execute
shell: bash
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
if [ -n "${FAIL_COMMAND}" ]; then
echo "Executing fail command:";
echo "${FAIL_COMMAND}";
eval "${FAIL_COMMAND}" || true;
fi;
sleep ${PAUSE};
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
if [ -n "${WORKDIR}" ]; then
cd "${WORKDIR}"
fi
retry ${COMMAND}
env:
RETRIES: ${{ inputs.retries }}
PAUSE: ${{ inputs.pause }}
COMMAND: ${{ inputs.command }}
WORKDIR: ${{ inputs.workdir }}
FAIL_COMMAND: ${{ inputs.fail_command }}
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载