Skip to content

Commit 00b5938

Browse files
authored
Harden CI workflows (#222)
Signed-off-by: Tamal Saha <tamal@appscode.com>
1 parent 289a185 commit 00b5938

5 files changed

Lines changed: 82 additions & 45 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ jobs:
1919
runs-on: ubuntu-24.04
2020
steps:
2121
- name: Set up Go 1.25
22-
uses: actions/setup-go@v5
22+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
2323
with:
2424
go-version: '1.25'
2525
id: go
2626

2727
- name: Check out code into the Go module directory
28-
uses: actions/checkout@v4
28+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2929

3030
- name: Prepare Host
3131
run: |

.github/workflows/release-tracker.yml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,25 @@ concurrency:
99
cancel-in-progress: true
1010
jobs:
1111
build:
12+
if: github.event.pull_request.merged == true
1213
runs-on: ubuntu-24.04
1314

1415
steps:
15-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1617

17-
- name: Prepare git
18-
env:
19-
GITHUB_USER: 1gtm
20-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
21-
run: |
22-
git config --global user.name "${GITHUB_USER}"
23-
git config --global user.email "${GITHUB_USER}@appscode.com"
24-
git remote set-url origin https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
25-
26-
- name: Install GitHub CLI
27-
run: |
28-
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
29-
sudo mv bin/hub /usr/local/bin
18+
- name: Generate LGTM App token
19+
id: lgtm-app-token
20+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
21+
with:
22+
client-id: ${{ secrets.LGTM_APP_CLIENT_ID }}
23+
private-key: ${{ secrets.LGTM_APP_PRIVATE_KEY }}
24+
owner: ${{ github.repository_owner }}
25+
repositories: CHANGELOG
26+
permission-pull-requests: write
3027

3128
- name: Update release tracker
32-
if: |
33-
github.event.action == 'closed' &&
34-
github.event.pull_request.merged == true
3529
env:
36-
GITHUB_USER: 1gtm
37-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
30+
GITHUB_USER: ${{ github.actor }}
31+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
3832
run: |
3933
./hack/scripts/update-release-tracker.sh

.github/workflows/release.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@ jobs:
1313
build:
1414
name: Build
1515
runs-on: ubuntu-24.04
16+
permissions:
17+
contents: write
1618
steps:
1719
- name: Check out code into the Go module directory
18-
uses: actions/checkout@v1
20+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
21+
with:
22+
fetch-depth: 1
23+
fetch-tags: true
1924

2025
- name: Print version info
2126
id: semver
@@ -24,12 +29,12 @@ jobs:
2429
2530
- name: Set up QEMU
2631
id: qemu
27-
uses: docker/setup-qemu-action@v3
32+
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
2833
with:
2934
cache-image: false
3035

3136
- name: Set up Docker Buildx
32-
uses: docker/setup-buildx-action@v3
37+
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
3338

3439
- name: Build
3540
env:
@@ -38,7 +43,7 @@ jobs:
3843
make release COMPRESS=yes
3944
4045
- name: Release
41-
uses: softprops/action-gh-release@v1
46+
uses: softprops/action-gh-release@26994186c0ac3ef5cae75ac16aa32e8153525f77 # v1
4247
if: startsWith(github.ref, 'refs/tags/')
4348
with:
4449
files: |
@@ -52,18 +57,39 @@ jobs:
5257
env:
5358
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5459

55-
- name: Install GitHub CLI
60+
- name: Classify release
61+
id: release-type
5662
run: |
57-
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
58-
sudo mv bin/hub /usr/local/bin
63+
ref="${GITHUB_REF}"
64+
if [[ "$ref" == refs/tags/* ]] \
65+
&& [[ "$ref" != *-alpha.* ]] \
66+
&& [[ "$ref" != *-beta.* ]] \
67+
&& [[ "$ref" != *-rc.* ]]; then
68+
echo "is_release=true" >> "$GITHUB_OUTPUT"
69+
else
70+
echo "is_release=false" >> "$GITHUB_OUTPUT"
71+
fi
72+
73+
- name: Generate LGTM App token
74+
id: lgtm-app-token
75+
if: steps.release-type.outputs.is_release == 'true'
76+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
77+
with:
78+
client-id: ${{ secrets.LGTM_APP_CLIENT_ID }}
79+
private-key: ${{ secrets.LGTM_APP_PRIVATE_KEY }}
80+
owner: appscode
81+
repositories: krew-index
82+
permission-contents: write
83+
permission-pull-requests: write
5984

6085
- name: Clone krew-index repository
86+
if: steps.release-type.outputs.is_release == 'true'
6187
env:
62-
GITHUB_USER: 1gtm
63-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
88+
GITHUB_USER: ${{ github.actor }}
89+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
6490
run: |
6591
KREW_INDEX_REPOSITORY=github.com/appscode/krew-index
66-
url="https://${GITHUB_USER}:${GITHUB_TOKEN}@${KREW_INDEX_REPOSITORY}.git"
92+
url="https://x-access-token:${GITHUB_TOKEN}@${KREW_INDEX_REPOSITORY}.git"
6793
cd $RUNNER_WORKSPACE
6894
git clone $url
6995
cd $(basename $KREW_INDEX_REPOSITORY)
@@ -72,9 +98,9 @@ jobs:
7298
7399
- name: Publish krew manifest
74100
env:
75-
GITHUB_USER: 1gtm
76-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
77-
if: startsWith(github.event.ref, 'refs/tags/')
101+
GITHUB_USER: ${{ github.actor }}
102+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
103+
if: steps.release-type.outputs.is_release == 'true'
78104
# if: startsWith(github.event.ref, 'refs/tags/') && (contains(github.ref, '-alpha.') || contains(github.ref, '-beta.') || contains(github.ref, '-rc.')) == false
79105
run: |
80106
cd $RUNNER_WORKSPACE/krew-index

.github/workflows/update-docs.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,42 @@ jobs:
1616
runs-on: ubuntu-24.04
1717
steps:
1818
- name: Set up Go 1.25
19-
uses: actions/setup-go@v5
19+
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
2020
with:
2121
go-version: '1.25'
2222
id: go
2323

24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2525

26-
- name: Install GitHub CLI
26+
27+
- name: Parse docs repository
28+
id: docs-repo
29+
env:
30+
DOCS_REPOSITORY: ${{ secrets.DOCS_REPOSITORY }}
2731
run: |
28-
curl -fsSL https://github.com/github/hub/raw/master/script/get | bash -s 2.14.1
29-
sudo mv bin/hub /usr/local/bin
32+
# DOCS_REPOSITORY is expected to be of the form: <host>/<owner>/<name>
33+
path="${DOCS_REPOSITORY#*/}"
34+
echo "owner=${path%%/*}" >> "$GITHUB_OUTPUT"
35+
echo "name=${path##*/}" >> "$GITHUB_OUTPUT"
36+
37+
- name: Generate LGTM App token
38+
id: lgtm-app-token
39+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
40+
with:
41+
client-id: ${{ secrets.LGTM_APP_CLIENT_ID }}
42+
private-key: ${{ secrets.LGTM_APP_PRIVATE_KEY }}
43+
owner: ${{ steps.docs-repo.outputs.owner }}
44+
repositories: ${{ steps.docs-repo.outputs.name }}
45+
permission-contents: write
46+
permission-pull-requests: write
3047

3148
- name: Clone charts repository
3249
env:
33-
GITHUB_USER: 1gtm
34-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
50+
GITHUB_USER: ${{ github.actor }}
51+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
3552
DOCS_REPOSITORY: ${{ secrets.DOCS_REPOSITORY }}
3653
run: |
37-
url="https://${GITHUB_USER}:${GITHUB_TOKEN}@${DOCS_REPOSITORY}.git"
54+
url="https://x-access-token:${GITHUB_TOKEN}@${DOCS_REPOSITORY}.git"
3855
cd $RUNNER_WORKSPACE
3956
git clone $url
4057
cd $(basename $DOCS_REPOSITORY)
@@ -43,8 +60,8 @@ jobs:
4360
4461
- name: Update docs
4562
env:
46-
GITHUB_USER: 1gtm
47-
GITHUB_TOKEN: ${{ secrets.LGTM_GITHUB_TOKEN }}
63+
GITHUB_USER: ${{ github.actor }}
64+
GITHUB_TOKEN: ${{ steps.lgtm-app-token.outputs.token }}
4865
DOCS_REPOSITORY: ${{ secrets.DOCS_REPOSITORY }}
4966
run: |
5067
export DOCS_ROOT=$RUNNER_WORKSPACE/$(basename $DOCS_REPOSITORY)

hack/scripts/update-release-tracker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ case $GITHUB_BASE_REF in
6969
;;
7070
esac
7171

72-
hub api "$api_url" -f body="$msg"
72+
gh api "$api_url" -f body="$msg"

0 commit comments

Comments
 (0)