Skip to content

Commit 728ff6f

Browse files
committed
Create example workflow
1 parent a298df2 commit 728ff6f

File tree

8 files changed

+178
-0
lines changed

8 files changed

+178
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# This file implements a waiting loop to check for signed files from OSSign.
2+
3+
# You need to create the environment "Signatures" (or another name) in your repository
4+
# and set a waiting period to change the interval. If you do not set a waiting period, this workflow will run again directly after it has finished every time.
5+
name: OSSign Waiting Loop
6+
7+
on:
8+
# You can also manually start this workflow with the ID printed out in the dispatch workflow
9+
workflow_dispatch:
10+
inputs:
11+
workflow_id:
12+
description: 'The workflow ID from dispatch'
13+
required: true
14+
type: string
15+
attempt:
16+
required: false
17+
description: 'The attempt number'
18+
type: number
19+
default: 1
20+
max_attempts:
21+
required: false
22+
description: 'The maximum number of attempts (times the waiting period duration you set in the environment gives the max wait time, e.g. 30 minutes * 48 = 24 hours)'
23+
type: number
24+
default: 100
25+
26+
jobs:
27+
wait-and-check:
28+
runs-on: ubuntu-latest
29+
30+
# This job uses an environment with a wait period set in the policy to work around the fact that you cannot pause workflows
31+
environment: Signatures
32+
33+
permissions:
34+
# Needs actions: write to be able to dispatch workflows
35+
actions: write
36+
37+
# Uses contents: write to be able to read and write workflow artifacts
38+
contents: write
39+
steps:
40+
41+
# Checks if the attempt threshold was reached, if yes, exits with error
42+
- name: Check if the threshold has been reached
43+
shell: bash
44+
run: |
45+
if [ ${{ github.event.inputs.attempt }} -gt ${{ github.event.inputs.max_attempts }} ]; then
46+
echo "Maximum number of attempts reached, exiting."
47+
exit 1
48+
fi
49+
50+
- name: Check if signing is finished
51+
id: check
52+
uses: ossign/actions/workflow/dispatch@main
53+
with:
54+
username: ${{ secrets.OSSIGN_USER }}
55+
token: ${{ secrets.OSSIGN_TOKEN }}
56+
single_check: ${{ github.event.inputs.workflow_id }}
57+
58+
# You can replace this step with another that downloads the signed artifacts and uploads them to releases
59+
# The data returnjed in signed_artifacts is:
60+
# [
61+
# {
62+
# "id": "Release artifact ID",
63+
# "name": "Filename.exe",
64+
# "url": "https://api.github.com/repos/OSSign/exampleuser--examplerepo/releases/assets/[releaseArtifactID]",
65+
# "browser_download_url": "https://github.com/OSSign/exampleuser--examplerepo/releases/download/[releaseArtifactID]/Filename.exe"
66+
# }
67+
# ]
68+
- name: If artifacts were returned, we are done!
69+
if: steps.check.outputs.signed_artifacts != ''
70+
run: |
71+
echo "Signing complete, signed artifacts: ${{ steps.check.outputs.signed_artifacts }}"
72+
73+
74+
# If the signature was not finished, increase the attempt counter and restart the workflow
75+
- name: Increase attempt counter
76+
if: steps.check.outputs.signed_artifacts == ''
77+
id: increased
78+
run: |
79+
echo "Attempt ${{ github.event.inputs.attempt }} failed, will try again."
80+
echo "attempt_no=$(( ${{ github.event.inputs.attempt }} + 1 ))" >> $GITHUB_OUTPUT
81+
82+
- name: If signing is not finished, restart the workflow
83+
if: steps.check.outputs.signed_artifacts == ''
84+
uses: benc-uk/workflow-dispatch@v1
85+
with:
86+
workflow: waiting-loop.yml
87+
inputs: |
88+
{
89+
"workflow_id": "${{ github.event.inputs.workflow_id }}",
90+
"attempt": "${{ steps.increased.outputs.attempt_no }}"
91+
}

.github/workflows/win-build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This file will build the program and dispatch it to OSSign for signing.
2+
# It will then start a waiting loop with the workflow file wait-signature to wait for the signed files to appear
3+
name: Build and Dispatch
4+
5+
on:
6+
push:
7+
tags: ['*.*.*']
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
permissions:
13+
# Needs actions: write to be able to dispatch workflows
14+
actions: write
15+
contents: read
16+
steps:
17+
# Checkout the code and build the program
18+
# to make sure everything works as expected
19+
- uses: actions/checkout@v5
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version: '1.25.1'
25+
26+
- name: Build the program
27+
run: go build -o myprogram.exe main.go
28+
29+
30+
# Dispatch a request to the OSSign repo for build + signing
31+
- name: Dispatch to OSSign
32+
uses: ossign/actions/workflow/dispatch@main
33+
with:
34+
# You receive the username and token from OSSign after your application has been approved
35+
username: ${{ secrets.OSSIGN_USER }}
36+
token: ${{ secrets.OSSIGN_TOKEN }}
37+
38+
# If you want to keep the workflow running until you have the signed file, you can change this to false
39+
# Bear in mind that it might sometimes take a while before the dispatch is approved, and this will keep the workflow running and billing if you are using a non-free runner
40+
dispatch_only: true
41+
42+
# Echo the workflow ID for debugging purposes
43+
- run: |
44+
echo "Received workflow ID: ${{ steps.dispatch.outputs.workflow_id }}"
45+
46+
# Starts the waiting loop, only required with dispatch_only: true
47+
# This will start the waiting-loop.yml workflow. For more information, see that file.
48+
- name: Start the waiting loop
49+
uses: benc-uk/workflow-dispatch@v1
50+
with:
51+
workflow: wait-signature.yml
52+
inputs: |
53+
{ "workflow_id": "${{ steps.dispatch.outputs.workflow_id }}" }

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
# example-workflow
22
This is an example workflow with instructions on how to set up the remote approval flow for OSSign
3+
4+
## .github/workflows/win-build.yml
5+
Builds your application and then dispatches a request to OSSign for signing. After dispatching, it starts a waiting loop to wait for the signed files to be available.
6+
7+
### Set the secrets
8+
To use this workflow, you need to set the following secrets in your GitHub repository. You will get these details from OSSign after your application has been approved for signing.
9+
- `OSSIGN_USER`: Your OSSign username
10+
- `OSSIGN_TOKEN`: Your OSSign token
11+
12+
## .github/workflows/wait-signature.yml
13+
This workflow is started by the waiting loop in the build workflow. It periodically checks with OSSign to see if the signing is complete. Once the signed files are available, you can add steps to download and use them as needed.
14+
15+
### Waiting loop setup
16+
To set up the waiting loop, start by creating a new environment:
17+
1. Go to your GitHub repository.
18+
2. Click on "Settings" > "Environments".![alt text](docs/image-2.png)
19+
20+
3. Create a new environment named `Signatures`. ![alt text](docs/image.png)
21+
22+
4. In the environment settings, check the "Wait timer" option and set it to 20 minutes ![alt text](docs/image-1.png)
23+
24+
5. Click "Save protection rules".
25+
26+
When setting the secrets, those need to be set outside of the environment.

docs/image-1.png

40.3 KB
Loading

docs/image-2.png

9.12 KB
Loading

docs/image.png

7.86 KB
Loading

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/ossign/example-workflow
2+
3+
go 1.25.2

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello, World!")
7+
}

0 commit comments

Comments
 (0)