Skip to content

Commit cf7622e

Browse files
committed
Base rework of github actions, WIP
1 parent ae6e076 commit cf7622e

File tree

8 files changed

+140
-80
lines changed

8 files changed

+140
-80
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "Codegen and Test"
2+
description: "Run go generate and go test"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- run: go generate ./...
7+
shell: bash
8+
- run: go test ./...
9+
shell: bash
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "Discord Webhook"
2+
description: "Send PR info to Discord"
3+
inputs:
4+
webhook-url:
5+
description: "Discord webhook URL"
6+
required: true
7+
pr-title:
8+
description: "Title of the pull request"
9+
required: false
10+
pr-body:
11+
description: "Body of the pull request"
12+
required: false
13+
pr-url:
14+
description: "URL of the pull request"
15+
required: false
16+
runs:
17+
using: "composite"
18+
steps:
19+
- uses: tsickert/discord-webhook@v7.0.0
20+
with:
21+
webhook-url: ${{ inputs.webhook-url }}
22+
embed-title: ${{ inputs.pr-title }}
23+
embed-description: ${{ inputs.pr-body }}
24+
embed-url: ${{ inputs.pr-url }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "Setup Go"
2+
description: "Checkout and setup Go using go.mod"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- uses: actions/checkout@v4
7+
- uses: actions/setup-go@v5
8+
with:
9+
go-version-file: 'go.mod'

.github/workflows/auto-tag.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Auto Tag
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
tag:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Needed to access all tags
17+
18+
- name: Create tag using commit message
19+
id: tagger
20+
uses: mathieudutour/github-tag-action@v6.1
21+
with:
22+
github_token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Print new tag
25+
run: |
26+
echo "Tagged version: ${{ steps.tagger.outputs.new_tag }}"
Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# This workflow will: build gomud for multiple os/architectures
2-
# archive the binaries and create a new release for users to easily download
3-
41
name: Build and release
52

63
on:
@@ -18,33 +15,14 @@ jobs:
1815
test:
1916
runs-on: ubuntu-latest
2017
steps:
21-
- name: Checkout repository
22-
uses: actions/checkout@v4
23-
24-
- name: Show version
25-
run: echo 'Releasing version $RELEASE_VERSION'
26-
27-
- name: Set up Go
28-
uses: actions/setup-go@v5
29-
with:
30-
go-version-file: 'go.mod'
31-
32-
- name: Run code generation
33-
run: go generate ./...
34-
35-
- name: Run tests
36-
run: go test ./...
18+
- uses: ./.github/actions/setup-go
19+
- uses: ./.github/actions/codegen-and-test
3720

3821
build:
3922
runs-on: ubuntu-latest
40-
needs: 'test'
23+
needs: test
4124
steps:
42-
- uses: actions/checkout@v4
43-
44-
- name: Set up Go
45-
uses: actions/setup-go@v5
46-
with:
47-
go-version-file: 'go.mod'
25+
- uses: ./.github/actions/setup-go
4826

4927
- name: Create bin directory
5028
run: mkdir -p bin/
@@ -75,7 +53,7 @@ jobs:
7553

7654
release:
7755
runs-on: ubuntu-latest
78-
needs: "build"
56+
needs: build
7957
steps:
8058
- uses: actions/checkout@v4
8159

@@ -88,8 +66,7 @@ jobs:
8866
- name: Set short git commit SHA
8967
id: vars
9068
run: |
91-
calculatedSha=$(git rev-parse --short ${{ github.sha }})
92-
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
69+
echo "COMMIT_SHORT_SHA=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_ENV
9370
9471
- name: Archive release
9572
run: zip -r bin/${{ env.RELEASE_FILENAME }}-${{ env.RELEASE_VERSION }}.zip bin/
@@ -102,26 +79,3 @@ jobs:
10279
fail_on_unmatched_files: true
10380
env:
10481
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105-
106-
message:
107-
runs-on: ubuntu-latest
108-
steps:
109-
- uses: actions/github-script@v6
110-
id: get_pr_data
111-
with:
112-
script: |
113-
return (
114-
await github.rest.repos.listPullRequestsAssociatedWithCommit({
115-
commit_sha: context.sha,
116-
owner: context.repo.owner,
117-
repo: context.repo.repo,
118-
})
119-
).data[0];
120-
- name: Discord Webhook Action
121-
uses: tsickert/discord-webhook@v7.0.0
122-
with:
123-
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
124-
embed-title: ${{ steps.get_pr_data.outputs.result && fromJson(steps.get_pr_data.outputs.result).title || '🎉 New update on `master` branch' }}
125-
embed-description: ${{ steps.get_pr_data.outputs.result && fromJson(steps.get_pr_data.outputs.result).body || 'No description provided.' }}
126-
embed-url: ${{ steps.get_pr_data.outputs.result && fromJson(steps.get_pr_data.outputs.result).html_url || github.event.compare }}
127-
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Notify Discord
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
notify-discord:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Get PR Metadata
14+
if: github.event_name == 'pull_request'
15+
uses: actions/github-script@v6
16+
id: pr_meta
17+
with:
18+
script: |
19+
core.setOutput('title', context.payload.pull_request.title || '')
20+
core.setOutput('body', context.payload.pull_request.body || '')
21+
core.setOutput('url', context.payload.pull_request.html_url || '')
22+
23+
- name: Get Release Metadata
24+
if: github.event_name == 'release'
25+
uses: actions/github-script@v6
26+
id: release_meta
27+
with:
28+
script: |
29+
core.setOutput('title', context.payload.release.name || context.payload.release.tag_name || '')
30+
core.setOutput('body', context.payload.release.body || '')
31+
core.setOutput('url', context.payload.release.html_url || '')
32+
33+
- name: Send Discord Message
34+
uses: ./.github/actions/discord-webhook
35+
with:
36+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
37+
pr-title: ${{ steps.pr_meta.outputs.title }}${{ steps.release_meta.outputs.title }}
38+
pr-body: ${{ steps.pr_meta.outputs.body }}${{ steps.release_meta.outputs.body }}
39+
pr-url: ${{ steps.pr_meta.outputs.url }}${{ steps.release_meta.outputs.url }}
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
2-
31
name: Docker Package
42

53
on:
@@ -14,54 +12,40 @@ on:
1412
- master
1513

1614
env:
17-
# Use docker.io for Docker Hub if empty
1815
REGISTRY: ghcr.io
19-
# github.repository as <account>/<repo>
2016
IMAGE_NAME: ${{ github.repository }}
2117
RELEASE_VERSION: ${{ github.ref_name }}
2218

2319
jobs:
2420
package:
2521
runs-on: ubuntu-latest
26-
27-
# Sets the permissions granted to the GITHUB_TOKEN for the actions in this job.
2822
permissions:
2923
contents: read
3024
packages: write
3125
attestations: write
3226
id-token: write
33-
3427
steps:
35-
- name: Checkout repository
36-
uses: actions/checkout@v4
28+
- uses: ./.github/actions/setup-go
3729

38-
# https://github.com/docker/login-action
3930
- name: Log in to the Container registry ${{ env.REGISTRY }}
4031
if: github.event_name != 'pull_request'
4132
uses: docker/login-action@v3
4233
with:
4334
registry: ${{ env.REGISTRY }}
4435
username: ${{ github.actor }}
45-
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
4636
password: ${{ secrets.GITHUB_TOKEN }}
4737

48-
# https://github.com/docker/metadata-action
4938
- name: Extract metadata (tags, labels) for Docker
5039
id: meta
5140
uses: docker/metadata-action@v5
5241
with:
5342
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
54-
# generate Docker tags based on the following events/attributes
5543
tags: |
56-
# set latest tag for master branch
5744
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
5845
type=ref,event=tag
5946
type=ref,event=pr
6047
type=sha
6148
62-
# https://github.com/docker/build-push-action
63-
# For pull request, only ensures that the docker build succeeds, does not push the image.
64-
# See: https://github.com/docker/build-push-action/issues/751
6549
- name: Build and push Docker image
6650
id: push
6751
uses: docker/build-push-action@v6
@@ -72,12 +56,10 @@ jobs:
7256
tags: ${{ steps.meta.outputs.tags }}
7357
labels: ${{ steps.meta.outputs.labels }}
7458

75-
# https://github.com/actions/attest-build-provenance
7659
- name: Generate artifact attestation
7760
if: github.event_name != 'pull_request'
7861
uses: actions/attest-build-provenance@v2
7962
with:
80-
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
63+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
8164
subject-digest: ${{ steps.push.outputs.digest }}
82-
# https://github.com/actions/attest-build-provenance/issues/71#issuecomment-2108140285
8365
push-to-registry: false

.github/workflows/run-tests.yml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,32 @@ jobs:
99
test:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/setup-go
13+
- uses: ./.github/actions/codegen-and-test
1314

14-
- name: Set up Go
15-
uses: actions/setup-go@v5
15+
pr-notification:
16+
runs-on: ubuntu-latest
17+
if: github.event_name == 'pull_request'
18+
steps:
19+
- name: Extract PR Metadata
20+
uses: actions/github-script@v6
21+
id: get_pr_data
1622
with:
17-
go-version-file: 'go.mod'
23+
script: |
24+
const pr = context.payload.pull_request;
25+
core.setOutput('title', pr.title);
26+
core.setOutput('body', pr.body);
27+
core.setOutput('url', pr.html_url);
1828
19-
- name: Run code generation
20-
run: go generate ./...
29+
- name: Debug PR Data Outputs
30+
run: |
31+
echo "Title: ${{ steps.get_pr_data.outputs.title }}"
32+
echo "Body: ${{ steps.get_pr_data.outputs.body }}"
33+
echo "URL: ${{ steps.get_pr_data.outputs.url }}"
2134
22-
- name: Run tests
23-
run: make test
35+
- uses: ./.github/actions/discord-webhook
36+
with:
37+
webhook-url: ${{ secrets.DISCORD_WEBHOOK_URL }}
38+
pr-title: ${{ steps.get_pr_data.outputs.title }}
39+
pr-body: ${{ steps.get_pr_data.outputs.body }}
40+
pr-url: ${{ steps.get_pr_data.outputs.url }}

0 commit comments

Comments
 (0)