Skip to content

Commit

Permalink
Merge pull request #10 from hey-car/ci/docker-base
Browse files Browse the repository at this point in the history
feat: transformed action into composite
  • Loading branch information
piximos authored Mar 26, 2024
2 parents 3b79696 + 7c21be6 commit 7c1bb22
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 63 deletions.
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# actions-label-semaphore

This action manage a semaphore system using labels in a remote repository.

```yaml
container:
image: <..some-img..>
steps:
- name: Label Semaphore
uses: hey-car/action-label-semaphore@<..some-version..>
env:
GITHUB_TOKEN: "<..some-token-with-access..>"
with:
pr-label: "<..some-label-name..>"
argo-app-path: "<..some-file-path..>"
argo-revision-path: "<..some-yaml-path..>"
argo-repo: "<..some-repo-name..>"
desired-revision: "<..some-tag..>"
```
83 changes: 62 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ inputs:
pr-label:
description: The label to use for the semaphore
required: true
pr-number:
description: The current pull request number
required: true
argo-repo:
description: The repository to update with the semaphore version
required: true
Expand All @@ -40,26 +37,70 @@ inputs:
argo-app-path:
description: The path to the file to update in the repository
required: true
semaphore-action:
description: The action to perform on the semaphore
required: true
desired-revision:
description: The desired revision to deploy
required: true


runs:
using: 'docker'
image: Dockerfile
env:
DEBUG_MODE: ${{ inputs.debug-mode }}
LOG_LEVEL: ${{ inputs.log-level }}
LOG_TIMESTAMPED: ${{ inputs.log-timestamped }}
PR_LABEL: ${{ inputs.pr-label }}
PR_NUMBER: ${{ inputs.pr-number }}
ARGO_REPO: ${{ inputs.argo-repo }}
ARGO_APP_PATH: ${{ inputs.argo-app-path }}
PR_USE_ALPHA_CHANNEL: ${{ inputs.use-alpha-channel }}
ARGO_REVISION_PATH: ${{ inputs.argo-revision-path }}
SEMAPHORE_ACTION: ${{ inputs.semaphore-action }}
DESIRED_REVISION: ${{ inputs.desired-revision }}
using: 'composite'
steps:
- name: setup
shell: bash
id: setup
run: |
echo "scripts-path=${GITHUB_ACTION_PATH}" >>"${GITHUB_OUTPUT}"
- name: Sync PR Environment
if: github.event_name == 'pull_request' && github.event.action != 'closed' && github.event.action != 'labeled' && github.event.action != 'unlabeled' && contains(github.event.pull_request.labels.*.name, inputs.pr-label)
run: '${{ steps.setup.outputs.scripts-path }}/scripts/script.sh'
shell: bash
env:
# Default conf
DEBUG_MODE: ${{ inputs.debug-mode }}
LOG_LEVEL: ${{ inputs.log-level }}
LOG_TIMESTAMPED: ${{ inputs.log-timestamped }}
PR_LABEL: ${{ inputs.pr-label }}
PR_NUMBER: ${{ github.event.pull_request.number }}
ARGO_REPO: ${{ inputs.argo-repo }}
ARGO_APP_PATH: ${{ inputs.argo-app-path }}
PR_USE_ALPHA_CHANNEL: ${{ inputs.use-alpha-channel }}
ARGO_REVISION_PATH: ${{ inputs.argo-revision-path }}
# Specific conf
DESIRED_REVISION: ${{ inputs.desired-revision }}
SEMAPHORE_ACTION: 'sync'
- name: Deploy PR Environment
if: github.event_name == 'pull_request' && github.event.action == 'labeled' && contains(github.event.pull_request.labels.*.name, inputs.pr-label)
run: '${{ steps.setup.outputs.scripts-path }}/scripts/script.sh'
# run: ${{ github.action_path }}/scripts/script.sh
shell: bash
env:
# Default conf
DEBUG_MODE: ${{ inputs.debug-mode }}
LOG_LEVEL: ${{ inputs.log-level }}
LOG_TIMESTAMPED: ${{ inputs.log-timestamped }}
PR_LABEL: ${{ inputs.pr-label }}
PR_NUMBER: ${{ github.event.pull_request.number }}
ARGO_REPO: ${{ inputs.argo-repo }}
ARGO_APP_PATH: ${{ inputs.argo-app-path }}
PR_USE_ALPHA_CHANNEL: ${{ inputs.use-alpha-channel }}
ARGO_REVISION_PATH: ${{ inputs.argo-revision-path }}
# Specific conf
DESIRED_REVISION: ${{ inputs.desired-revision }}
SEMAPHORE_ACTION: 'publish'
- name: Remove PR Environment
if: github.event_name == 'pull_request' && (github.event.action == 'unlabeled' || github.event.action == 'closed') && !contains(github.event.pull_request.labels.*.name, inputs.pr-label)
run: '${{ steps.setup.outputs.scripts-path }}/scripts/script.sh'
# run: ${{ github.action_path }}/scripts/script.sh
shell: bash
env:
# Default conf
DEBUG_MODE: ${{ inputs.debug-mode }}
LOG_LEVEL: ${{ inputs.log-level }}
LOG_TIMESTAMPED: ${{ inputs.log-timestamped }}
PR_LABEL: ${{ inputs.pr-label }}
PR_NUMBER: ${{ github.event.pull_request.number }}
ARGO_REPO: ${{ inputs.argo-repo }}
ARGO_APP_PATH: ${{ inputs.argo-app-path }}
PR_USE_ALPHA_CHANNEL: ${{ inputs.use-alpha-channel }}
ARGO_REVISION_PATH: ${{ inputs.argo-revision-path }}
# Specific conf
SEMAPHORE_ACTION: 'unpublish'
9 changes: 1 addition & 8 deletions scripts/label-semaphore/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@ mkdir "${_work_dir}"

## Label Checks
log_out "Starting Label Semaphore for Publishing PR Environment!"
log_out "Sanity check: Checking label on current Pull Request."
_label_present_on_current_pr="$(check_label_on_current_pr "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}" "${PR_LABEL}")"
log_out "Was the label present on current Pull Requests? ${_label_present_on_current_pr}"

if [[ -z "$(check_bool "${_label_present_on_current_pr}")" ]]; then
log_out "The '${PR_LABEL}' is not present on current PR #${PR_NUMBER}. Aborting." "PANIC" 2
fi

log_out "Checking label on other Pull Requests."
_label_present_on_other_prs="$(check_label_on_other_prs "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}" "${PR_LABEL}")"
log_out "Was the label present on other Pull Requests? ${_label_present_on_other_prs}"

if [[ "$(check_bool "${_label_present_on_current_pr}")" && "$(check_bool "${_label_present_on_other_prs}")" ]]; then
if [[ "$(check_bool "${_label_present_on_other_prs}")" ]]; then
while read -r _pr; do
log_out "Removing label from pull request #${_pr}"
remove_label_from_pr "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${_pr}" "${PR_LABEL}"
Expand Down
7 changes: 0 additions & 7 deletions scripts/label-semaphore/sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ mkdir "${_work_dir}"

## Label Checks
log_out "Starting Label Semaphore for Publishing PR Environment!"
log_out "Sanity check: Checking label on current Pull Request."
_label_present_on_current_pr="$(check_label_on_current_pr "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}" "${PR_LABEL}")"
log_out "Was the label present on current Pull Requests? ${_label_present_on_current_pr}"

if [[ -z "$(check_bool "${_label_present_on_current_pr}")" ]]; then
log_out "The '${PR_LABEL}' is not present on current PR #${PR_NUMBER}. Aborting." "PANIC" 2
fi

## Semaphore Operations
log_out "Fetching target file to update"
Expand Down
11 changes: 0 additions & 11 deletions scripts/label-semaphore/unpublish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ mkdir "${_work_dir}"
## Label Checks

log_out "Starting Label Semaphore for Unpublishing PR Environment!"
log_out "Sanity check: Checking label on current Pull Request."
_label_present_on_current_pr="$(check_label_on_current_pr "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}" "${PR_LABEL}")"
log_out "Was the label present on current Pull Requests? ${_label_present_on_current_pr}"

log_out "Checking State on current Pull Request."
_current_pr_state="$(check_status_of_pr "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}")"
log_out "Current Pull Request is: ${_current_pr_state}"

if [[ "$(check_bool "${_label_present_on_current_pr}")" && "${_current_pr_state}" != "CLOSED" && "${_current_pr_state}" != "MERGED" ]]; then
log_out "The '${PR_LABEL}' is present on current PR #${PR_NUMBER} while it's still open. Aborting." "PANIC" 2
fi

log_out "Checking label on other Pull Requests."
_label_present_on_other_prs="$(check_label_on_other_prs "${GITHUB_REPOSITORY_OWNER}" "${REPO_NAME}" "${PR_NUMBER}" "${PR_LABEL}")"
Expand Down

0 comments on commit 7c1bb22

Please sign in to comment.