forked from sigstore/root-signing
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (91 loc) · 3.81 KB
/
stable-timestamp.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# 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@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
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 }}