Skip to content

Commit 152b115

Browse files
authored
Create release.yml
1 parent 69f0761 commit 152b115

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

.github/workflows/release.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
# stolen from https://github.com/laluka/bypass-url-parser/blob/main/.github/workflows/release.yml thx @laluka <3
3+
name: GitHub release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: "The version to tag, without the leading 'v'. If omitted, will initiate a dry run (no uploads)."
10+
type: string
11+
sha:
12+
description: "The full sha of the commit to be released. If omitted, the latest commit on the default branch will be used."
13+
default: ""
14+
type: string
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
build:
22+
name: Build
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
ref: ${{ inputs.sha }}
28+
29+
- name: Set local tag for version
30+
if: ${{ inputs.tag }}
31+
run: |
32+
# Set to Github Actor
33+
git config user.email "${{ github.actor }}@users.noreply.github.com"
34+
git config user.name "${{ github.actor }} (GitHub Actions)"
35+
git tag -m "v${{ inputs.tag }}" "v${{ inputs.tag }}"
36+
37+
- name: Install golang
38+
uses: actions/setup-go@v5
39+
40+
- name: "Build"
41+
run: |
42+
go mod tidy
43+
go build
44+
- name: "Upload binary"
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: octoscan
48+
path: ./octoscan
49+
50+
validate-tag:
51+
name: Validate tag
52+
runs-on: ubuntu-latest
53+
# If you don't set an input tag, it's a dry run (no uploads).
54+
if: ${{ inputs.tag }}
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
ref: master # We checkout the master branch to check for the commit
59+
- name: Check master branch
60+
if: ${{ inputs.sha }}
61+
run: |
62+
# Fetch the master branch since a shallow checkout is used by default
63+
git fetch origin master --unshallow
64+
if ! git branch --contains ${{ inputs.sha }} | grep -E '(^|\s)master$'; then
65+
echo "The specified sha is not on the master branch" >&2
66+
exit 1
67+
fi
68+
69+
tag-release:
70+
name: Tag release
71+
runs-on: ubuntu-latest
72+
needs: build
73+
# If you don't set an input tag, it's a dry run (no uploads).
74+
if: ${{ inputs.tag }}
75+
permissions:
76+
# For git tag
77+
contents: write
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
ref: ${{ inputs.sha }}
82+
- name: git tag
83+
run: |
84+
git config user.email "${{ github.actor }}@users.noreply.github.com"
85+
git config user.name "${{ github.actor }} (GitHub Actions)"
86+
git tag -m "v${{ inputs.tag }}" "v${{ inputs.tag }}"
87+
# If there is duplicate tag, this will fail. The publish to pypi action will have been a noop (due to skip
88+
# existing), so we make a non-destructive exit here
89+
git push --tags
90+
91+
publish-release:
92+
name: Publish to GitHub
93+
runs-on: ubuntu-latest
94+
needs: tag-release
95+
# If you don't set an input tag, it's a dry run (no uploads).
96+
if: ${{ inputs.tag }}
97+
permissions:
98+
# For GitHub release publishing
99+
contents: write
100+
steps:
101+
- uses: actions/download-artifact@v4
102+
with:
103+
name: octoscan
104+
path: ./octoscan
105+
- name: "Publish to GitHub"
106+
uses: softprops/action-gh-release@v2
107+
with:
108+
draft: true
109+
files: octoscan/*
110+
tag_name: v${{ inputs.tag }}

0 commit comments

Comments
 (0)