Skip to content

Commit 5735d55

Browse files
committed
setup core workflow files
1 parent 5d139cf commit 5735d55

File tree

7 files changed

+264
-2
lines changed

7 files changed

+264
-2
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
name: build
17+
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest]
21+
runs-on: ${{ matrix.os }}
22+
23+
steps:
24+
- name: checkout
25+
uses: actions/checkout@v4
26+
27+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected]
28+
with:
29+
bundler-cache: true
30+
31+
- name: bootstrap
32+
run: script/bootstrap
33+
34+
- name: build
35+
run: script/build

.github/workflows/lint.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: lint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lint:
14+
name: lint
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: checkout
19+
uses: actions/checkout@v4
20+
21+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected]
22+
with:
23+
bundler-cache: true
24+
25+
- name: bootstrap
26+
run: script/bootstrap
27+
28+
- name: lint
29+
run: script/lint

.github/workflows/release.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- lib/hooks/version.rb
10+
11+
permissions: {}
12+
13+
jobs:
14+
build:
15+
if: github.repository == 'github/hooks'
16+
permissions:
17+
contents: read
18+
runs-on: ubuntu-latest
19+
outputs:
20+
artifact-id: ${{ steps.upload-artifact.outputs.artifact-id }}
21+
gem_name: ${{ steps.build.outputs.gem_name }}
22+
gem_version: ${{ steps.build.outputs.gem_version }}
23+
gem_path: ${{ steps.build.outputs.gem_path }}
24+
25+
steps:
26+
- name: checkout
27+
uses: actions/checkout@v4
28+
with:
29+
persist-credentials: false
30+
31+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected]
32+
with:
33+
bundler-cache: false
34+
35+
- name: bootstrap
36+
run: script/bootstrap
37+
38+
# IMPORTANT: this step MUST export for the following outputs:
39+
# gem_name: the name of the gem - ex: "my-cool-gem"
40+
# gem_version: the version of the gem - ex: "1.0.0"
41+
# gem_path: the path/filename of the gem - ex: "my-cool-gem-1.0.0.gem"
42+
- name: build
43+
id: build
44+
run: script/build
45+
46+
- name: upload artifact
47+
uses: actions/[email protected]
48+
id: upload-artifact
49+
with:
50+
path: "${{ steps.build.outputs.gem_path }}"
51+
52+
release:
53+
needs: build
54+
environment: release
55+
runs-on: ubuntu-latest
56+
permissions:
57+
contents: write
58+
packages: write
59+
id-token: write
60+
steps:
61+
- uses: actions/checkout@v4
62+
with:
63+
persist-credentials: false
64+
65+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
66+
with:
67+
artifact-ids: ${{ needs.build.outputs.artifact-id }}
68+
69+
- name: Publish to GitHub Packages
70+
env:
71+
OWNER: ${{ github.repository_owner }}
72+
GEM_NAME: ${{ needs.build.outputs.gem_name }}
73+
GEM_VERSION: ${{ needs.build.outputs.gem_version }}
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
ARTIFACT_PATH: "artifact"
76+
run: |
77+
GEM_HOST_API_KEY=${GITHUB_TOKEN} gem push --key github --host https://rubygems.pkg.github.com/${OWNER} $ARTIFACT_PATH/${GEM_NAME}-${GEM_VERSION}.gem
78+
79+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected]
80+
with:
81+
bundler-cache: false
82+
83+
- name: bootstrap
84+
run: script/bootstrap
85+
86+
- name: Configure RubyGems Credentials
87+
uses: rubygems/configure-rubygems-credentials@e3f5097339179e0d4c7321ab44209e7e02446746 # pin@main
88+
89+
- name: sign ruby gem
90+
env:
91+
GEM_NAME: ${{ needs.build.outputs.gem_name }}
92+
GEM_VERSION: ${{ needs.build.outputs.gem_version }}
93+
ARTIFACT_PATH: "artifact"
94+
run: bundle exec sigstore-cli sign ${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem --bundle ${GEM_NAME}-${GEM_VERSION}.sigstore.json
95+
96+
- name: Publish to RubyGems
97+
env:
98+
GEM_NAME: ${{ needs.build.outputs.gem_name }}
99+
GEM_VERSION: ${{ needs.build.outputs.gem_version }}
100+
ARTIFACT_PATH: "artifact"
101+
run: gem push ${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem --attestation ${GEM_NAME}-${GEM_VERSION}.sigstore.json
102+
103+
- name: await gem
104+
env:
105+
GEM_NAME: ${{ needs.build.outputs.gem_name }}
106+
GEM_VERSION: ${{ needs.build.outputs.gem_version }}
107+
run: bundle exec rubygems-await "${GEM_NAME}:${GEM_VERSION}" --timeout 120
108+
109+
- name: GitHub Release
110+
env:
111+
GEM_NAME: ${{ needs.build.outputs.gem_name }}
112+
GEM_VERSION: ${{ needs.build.outputs.gem_version }}
113+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
ARTIFACT_PATH: "artifact"
115+
run: |
116+
gh release create "v${GEM_VERSION}" \
117+
"${ARTIFACT_PATH}/${GEM_NAME}-${GEM_VERSION}.gem" \
118+
"${GEM_NAME}-${GEM_VERSION}.sigstore.json" \
119+
--title "v${GEM_VERSION}" \
120+
--generate-notes
121+
122+
sign:
123+
needs: [build, release]
124+
runs-on: ubuntu-latest
125+
permissions:
126+
id-token: write
127+
attestations: write
128+
contents: read
129+
130+
steps:
131+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
132+
with:
133+
artifact-ids: ${{ needs.build.outputs.artifact-id }}
134+
135+
- name: attest build provenance
136+
uses: actions/[email protected]
137+
with:
138+
subject-path: "artifact/${{ needs.build.outputs.gem_path }}"
139+
140+
verify:
141+
permissions: {}
142+
needs: [build, release, sign]
143+
runs-on: ubuntu-latest
144+
145+
steps:
146+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
147+
with:
148+
artifact-ids: ${{ needs.build.outputs.artifact-id }}
149+
150+
- name: verify
151+
env:
152+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
OWNER: ${{ github.repository_owner }}
154+
REPO: ${{ github.event.repository.name }}
155+
ARTIFACT_PATH: "artifact/${{ needs.build.outputs.gem_path }}"
156+
run: gh attestation verify "$ARTIFACT_PATH" --repo ${OWNER}/${REPO} --signer-workflow ${OWNER}/${REPO}/.github/workflows/release.yml

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: test
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
ruby: [ '3.1.2', '3.1.4', '3.2.2', '3.2.3', '3.3.0', '3.3.1', '3.4.0', '3.4.2', '3.4.3', '3.4.4' ]
19+
20+
steps:
21+
- name: checkout
22+
uses: actions/checkout@v4
23+
24+
- uses: ruby/setup-ruby@13e7a03dc3ac6c3798f4570bfead2aed4d96abfb # [email protected]
25+
with:
26+
bundler-cache: true
27+
ruby-version: ${{ matrix.ruby }}
28+
29+
- name: bootstrap
30+
run: script/bootstrap
31+
32+
- name: test
33+
run: script/test

hooks.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "lib/version"
3+
require_relative "lib/hooks/version"
44

55
Gem::Specification.new do |spec|
66
spec.name = "hooks-ruby"
File renamed without changes.

script/build

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ set -e
44

55
source script/env "$@"
66

7-
echo "define your build script here"
7+
GEM_NAME=$(ls | grep gemspec | cut -d. -f1)
8+
GEM_VERSION=$(gem build $GEM_NAME.gemspec 2>&1 | grep Version | cut -d':' -f 2 | tr -d " \t\n\r")
9+
10+
if [[ "$CI" == "true" ]]; then
11+
echo "gem_name=$GEM_NAME" >> $GITHUB_OUTPUT
12+
echo "gem_version=$GEM_VERSION" >> $GITHUB_OUTPUT
13+
echo "gem_path=$GEM_NAME-$GEM_VERSION.gem" >> $GITHUB_OUTPUT
14+
fi
15+
16+
echo -e "📦 ${GREEN}successfully${OFF} built ${PURPLE}$GEM_NAME-$GEM_VERSION.gem${OFF}"

0 commit comments

Comments
 (0)