Repository navigation
91 lines (80 loc) · 2.76 KB
/
Copy pathci.yml
File metadata and controls
91 lines (80 loc) · 2.76 KB
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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
ruby-version: ["3.0", "3.1", "3.2", "3.3", "3.4", "4.0"]
steps:
- uses: actions/checkout@v5
- name: Set up Ruby ${{ matrix.ruby-version }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
- name: Run tests
run: ruby -Ilib -Itest -e "Dir['test/test_*.rb'].each { |f| require File.expand_path(f) }"
- name: Verify gem builds
run: gem build ipdata.gemspec
# After a push to the default branch, tag the commit and create the GitHub
# release when lib/ipdata/version.rb holds a version that is not tagged yet.
release:
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
outputs:
tag: ${{ steps.release.outputs.tag }}
created: ${{ steps.release.outputs.created }}
steps:
- uses: actions/checkout@v5
- name: Tag and release a new version
id: release
env:
GH_TOKEN: ${{ github.token }}
run: |
version=$(sed -nE 's/.*VERSION *= *"([^"]+)".*/\1/p' lib/ipdata/version.rb | head -1)
if [ -z "$version" ]; then
echo "Could not read the version from lib/ipdata/version.rb" >&2
exit 1
fi
tag="v${version}"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
status=0
git ls-remote --exit-code --tags origin "refs/tags/${tag}" > /dev/null || status=$?
case "$status" in
0)
echo "Tag ${tag} already exists; nothing to release."
echo "created=false" >> "$GITHUB_OUTPUT"
;;
2)
gh release create "${tag}" --target "$GITHUB_SHA" --title "${tag}" --generate-notes
echo "Created tag and release ${tag} from ${GITHUB_SHA}."
echo "created=true" >> "$GITHUB_OUTPUT"
;;
*)
echo "Could not check whether tag ${tag} exists (git ls-remote exited with ${status})." >&2
exit "$status"
;;
esac
# A tag created with the workflow token does not start other workflows, so
# the gem is published from this run through the reusable release workflow.
publish:
needs: release
if: needs.release.outputs.created == 'true'
permissions:
contents: write
id-token: write
uses: ./.github/workflows/release.yml
with:
tag: ${{ needs.release.outputs.tag }}
secrets: inherit