diff --git a/.github/workflows/pub_dev_push_event.yml b/.github/workflows/pub_dev_push_event.yml deleted file mode 100644 index 3600112..0000000 --- a/.github/workflows/pub_dev_push_event.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Publish Dev Push Event -on: - workflow_dispatch: - push: - branches: - - dev - -jobs: - publish_event: - runs-on: ubuntu-latest - name: Publish dev push - steps: - - run: | - curl -i \ - -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \ - https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \ - -d '{"event_type":"dev_push"}' diff --git a/.github/workflows/pub_master_push_event.yml b/.github/workflows/pub_master_push_event.yml deleted file mode 100644 index 0339a05..0000000 --- a/.github/workflows/pub_master_push_event.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Publish Master Push Event -on: - workflow_dispatch: - push: - branches: - - master - -jobs: - publish_event: - runs-on: ubuntu-latest - name: Publish master push - steps: - - run: | - curl -i \ - -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \ - https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \ - -d '{"event_type":"master_push"}' diff --git a/.github/workflows/pub_staging_push_event.yml b/.github/workflows/pub_staging_push_event.yml deleted file mode 100644 index 681c5cb..0000000 --- a/.github/workflows/pub_staging_push_event.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Publish Staging Push Event -on: - workflow_dispatch: - push: - branches: - - staging - -jobs: - publish_event: - runs-on: ubuntu-latest - name: Publish staging push - steps: - - run: | - curl -i \ - -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: token ${{ secrets.PUBLISH_PUSH_TOKEN }}" \ - https://api.github.com/repos/awalsh128/cache-apt-pkgs-action-ci/dispatches \ - -d '{"event_type":"staging_push"}' \ No newline at end of file diff --git a/.github/workflows/update_release_tags.yml b/.github/workflows/update_release_tags.yml new file mode 100644 index 0000000..0118a42 --- /dev/null +++ b/.github/workflows/update_release_tags.yml @@ -0,0 +1,29 @@ +name: Update Release Tags +on: + workflow_dispatch: + inputs: + version: + description: "Version tag to update to." + type: string + required: true + +permissions: + contents: write + +jobs: + update_release_tags: + runs-on: ubuntu-latest + name: Run update_release_tags.sh script. + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-depth: 0 + - name: Configure git identity + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Update tags + env: + CI: "true" + VERSION: ${{ github.event.inputs.version }} + run: ./scripts/release/update_release_tags.sh "${VERSION}" diff --git a/README.md b/README.md index 0a20b42..eab8ef4 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # cache-apt-pkgs-action [![License: Apache2](https://shields.io/badge/license-apache2-blue.svg)](https://github.com/awalsh128/fluentcpp/blob/master/LICENSE) -[![Master Test status](https://github.com/awalsh128/cache-apt-pkgs-action-ci/actions/workflows/master_test.yml/badge.svg)](https://github.com/awalsh128/cache-apt-pkgs-action-ci/actions/workflows/master_test.yml) -[![Dev Test status](https://github.com/awalsh128/cache-apt-pkgs-action-ci/actions/workflows/dev_test.yml/badge.svg)](https://github.com/awalsh128/cache-apt-pkgs-action-ci/actions/workflows/dev_test.yml) +[![Master Test status](https://github.com/awalsh128/cache-apt-pkgs-action/actions/workflows/action-tests.yml/badge.svg?branch=master)](https://github.com/awalsh128/cache-apt-pkgs-action/actions/workflows/action-tests.yml?query=branch%3Amaster) +[![Dev Test status](https://github.com/awalsh128/cache-apt-pkgs-action/actions/workflows/action-tests.yml/badge.svg?branch=dev)](https://github.com/awalsh128/cache-apt-pkgs-action/actions/workflows/action-tests.yml?query=branch%3Adev) This action allows caching of Advanced Package Tool (APT) package dependencies to improve workflow execution time instead of installing the packages on every run. diff --git a/scripts/release/copy_tag.sh b/scripts/release/copy_tag.sh new file mode 100755 index 0000000..efc7ccc --- /dev/null +++ b/scripts/release/copy_tag.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Point a (moving) tag, e.g. v1 or latest, at the commit of another tag. +# Run from anywhere inside a clone of this repository. + +set -euo pipefail + +# shellcheck source=lib.sh +source "$(dirname -- "$(realpath -- "${0}")")/lib.sh" +usage_msg=$(usage "${0}" " ") + +source_tag="${1:-}" +validate_arg "${source_tag}" "Source tag arg must be non-empty." "${usage_msg}" + +target_tag="${2:-}" +validate_arg "${target_tag}" "Target tag arg must be non-empty." "${usage_msg}" + +cd "$(git rev-parse --show-toplevel)" +git fetch origin --tags --force + +if ! git rev-parse --verify --quiet "refs/tags/${source_tag}" > /dev/null; then + echo "error: source tag '${source_tag}' does not exist." >&2 + exit 1 +fi + +confirm_prompt "Do you want to update '${target_tag}' from '${source_tag}'?" + +git tag -fa "${target_tag}" -m "Points ${target_tag} to ${source_tag}." "${source_tag}^{commit}" +git push --force origin "refs/tags/${target_tag}" diff --git a/scripts/release/lib.sh b/scripts/release/lib.sh new file mode 100755 index 0000000..4e35454 --- /dev/null +++ b/scripts/release/lib.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Shared helpers for the release scripts in this directory. +# Source this file; do not execute it directly. + +####################################### +# Yes or no prompt. Auto-confirms when CI=true or ASSUME_YES=1 so the +# scripts can also run from a GitHub workflow. +# Arguments: +# Message to display at prompt. +# Returns: +# 0 on yes, exits the script on no. +####################################### +function confirm_prompt { + if [[ "${CI:-}" == "true" || "${ASSUME_YES:-}" == "1" ]]; then + echo "${1} [auto-confirmed]" + return 0 + fi + while true; do + read -r -p "${1} [Y|n] " response + case ${response} in + [Yy]*) return 0 ;; + [Nn]*) exit 0 ;; + *) echo "Invalid option selected." ;; + esac + done +} + +####################################### +# Validate argument and exit if invalid. +# Arguments: +# Argument to validate. +# Message to display on error. +# Usage message. +# Returns: +# None, exits non-zero when the argument is empty. +####################################### +function validate_arg { + if [[ -z "${1:-}" ]]; then + printf 'error: %s\n%s\n' "${2}" "${3}" >&2 + exit 1 + fi +} + +####################################### +# Print out command usage. +# Arguments: +# Name of command. +# Parameters. +# Returns: +# Usage message. +####################################### +function usage { + echo "usage: $(basename "${1}") ${2}" +} diff --git a/scripts/release/update_release_tags.sh b/scripts/release/update_release_tags.sh new file mode 100755 index 0000000..bcc7be8 --- /dev/null +++ b/scripts/release/update_release_tags.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Move the floating release tags (v1 and latest) to a released version tag. +# Run from anywhere inside a clone of this repository. + +set -euo pipefail + +script_dir="$(dirname -- "$(realpath -- "${0}")")" +# shellcheck source=lib.sh +source "${script_dir}/lib.sh" +usage_msg=$(usage "${0}" "") + +version="${1:-}" +validate_arg "${version}" "Version tag arg must be non-empty." "${usage_msg}" + +"${script_dir}/copy_tag.sh" "${version}" v1 +"${script_dir}/copy_tag.sh" "${version}" latest