.github/workflows/stable-timestamp.yml #18
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
# | |
# Copyright 2021 The Sigstore Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
name: Stable Timestamp | |
permissions: read-all | |
# Execute this as a once a week cron job (in addition to stable-snapshot-timestamp) | |
on: | |
# Enable cron for re-signing timestamp every week. Timestamp is also | |
# regenerated in stable-snapshot-timestamp.yml | |
schedule: | |
- cron: '0 16 * * 5' # every Friday at 9am PST | |
workflow_dispatch: | |
inputs: | |
dry_run: | |
type: boolean | |
default: false | |
description: Does not trigger job, but checks on whether the job should run. | |
force_timestamp: | |
description: 'Whether to force a timestamp. Useful if workflow is within 5 days of a ceremony' | |
required: false | |
default: false | |
type: boolean | |
jobs: | |
check: | |
# This job checks whether timestamp should run. | |
runs-on: ubuntu-latest | |
outputs: | |
block_timestamp: ${{ steps.check.outputs.block_timestamp }} | |
env: | |
FORCE_TIMESTAMP: ${{ inputs.force_timestamp }} | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
with: | |
fetch-depth: 0 | |
- name: Determine whether to create a timestamp | |
id: check | |
shell: bash | |
run: | | |
set -euo pipefail | |
BRANCHES=$(git for-each-ref --format='%(refname:short)' | grep origin/ceremony/) | |
echo "${BRANCHES}" | |
# Check whether a ceremony was initiated within a week of the current date. | |
echo "block_timestamp=false" >> "${GITHUB_OUTPUT}" | |
# If we force a timestamp, exit early. | |
if [[ "${FORCE_TIMESTAMP}" ]]; then | |
exit | |
fi | |
ceremonyRegex="origin/ceremony/[0-9]{4}-[0-9]{2}-[0-9]{2}$" | |
for branch in ${BRANCHES} | |
do | |
if [[ "$branch" =~ ${ceremonyRegex} ]]; then | |
echo "found ceremony branch $branch" | |
branch_date=$(echo "${branch}" | cut -d '/' -f3) | |
days_diff=$(( ($(date -d "00:00" +%s) - $(date -d "${branch_date}" +%s)) / (24*3600) )) | |
if [[ "$days_diff" -lt 2 ]]; then | |
# Detected ceremony within 2 days of current date | |
echo "detected ceremony branch $branch within 2 days, stopping automated cron" | |
echo "block_timestamp=true" >> "${GITHUB_OUTPUT}" | |
fi | |
fi | |
done | |
run_timestamp_publish: | |
needs: check | |
if: (github.event_name == 'schedule' && github.repository == 'sigstore/root-signing' && needs.check.outputs.block_timestamp == 'false') || (github.event_name != 'schedule' && inputs.dry_run == false) # Don't run workflow in forks on cron | |
permissions: | |
id-token: 'write' | |
issues: 'write' | |
pull-requests: 'write' | |
contents: 'write' | |
actions: 'read' | |
uses: sigstore/root-signing/.github/workflows/reuseable-snapshot-timestamp.yml@main | |
with: | |
timestamp_key: 'gcpkms://projects/sigstore-root-signing/locations/global/keyRings/root/cryptoKeys/timestamp' | |
repo: 'repository/' | |
branch: main | |
provider: 'projects/163070369698/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | |
service_account: '[email protected]' | |
disable_snapshot: true | |
secrets: | |
token: ${{ secrets.SIGSTORE_ROOT_SIGNING_FINE_GRAINED_PAT }} |