git.iko.soy/typeable/oauth2-proxy
on master help sign in
feature: add release automation workflows (#2224)

* feature: add release automation workflows * deactivate provenancee because of behaviour change with buildx v0.10.0 * add changelog section extraction for github release notes * fix registry path; fix EOF * use correct version of golangci-lint; add additional workflow step for fetching all dependencies

commit2df301cc21d0012dcd890514dee1770acf3f1936 authorJan Larwig <jan@larwig.com> dateSat 20 Jan 2024, 21:14 (3 years ago) parentf88f09f
3 files changed+245
.github/workflows/create-release.yml+117 .github/workflows/publish-release.yml+126 RELEASE.md+2
.github/workflows/create-release.ymlnew file+117
@@ -0,0 +1,117 @@
1+name: Create Release
2+run-name: Create release ${{ inputs.version }}
3+
4+on:
5+ workflow_dispatch:
6+ inputs:
7+ version:
8+ description: 'Version for new release'
9+ required: true
10+
11+permissions:
12+ contents: write
13+ pull-requests: write
14+
15+jobs:
16+ release:
17+ runs-on: ubuntu-latest
18+ steps:
19+ - name: Check out code
20+ uses: actions/checkout@v3
21+ with:
22+ ref: master
23+ fetch-depth: 0
24+ fetch-tags: true
25+
26+ - name: Validate version
27+ id: validate
28+ run: |
29+ function ver { printf "%03d%03d%03d%03d" $(echo "$1" | tr '.' ' '); }
30+
31+ NEW_VERSION=${{ inputs.version }}
32+ NEW_VERSION=${NEW_VERSION#v} # Remove v prefix
33+
34+ LATEST_VERSION=$(git describe --abbrev=0 --tags)
35+ LATEST_VERSION=${LATEST_VERSION#v} # Remove v prefix
36+
37+ # check that new version can be parsed
38+ if [ ! $(ver $NEW_VERSION ) -gt $(ver 0) ]; then
39+ echo "::error::Entered version '${{ inputs.version }}' cannot be parsed"
40+ exit 1
41+ fi
42+
43+ # check version continuity
44+ if [ ! $(ver $LATEST_VERSION) -lt $(ver $NEW_VERSION) ]; then
45+ echo "::error::Entered version '${{ inputs.version }}' is smaller then latest version $LATEST_VERSION"
46+ exit 1
47+ fi
48+
49+ echo "version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
50+
51+ - name: Prepare Github Actions Bot
52+ run: |
53+ git config --local user.name "github-actions[bot]"
54+ git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
55+
56+ - name: Setup node
57+ uses: actions/setup-node@v3
58+ with:
59+ node-version: latest
60+
61+ - name: Update documentation
62+ run: |
63+ cd docs
64+
65+ FULL_VERSION=${{ steps.validate.outputs.version }}
66+ VERSION=${FULL_VERSION%.*}.x
67+
68+ if [ ! -d "versioned_docs/version-${VERSION}" ]; then
69+ npm ci
70+ npm run docusaurus docs:version ${VERSION}
71+
72+ git add .
73+ git commit -m "add new docs version ${VERSION}"
74+ fi
75+
76+ sed -i "s/(current release is .*)/(current release is \`v${FULL_VERSION}\`)/g" docs/installation.md
77+ sed -i "s/(current release is .*)/(current release is \`v${FULL_VERSION}\`)/g" versioned_docs/version-${VERSION}/installation.md
78+
79+ - name: Update Changelog
80+ run: |
81+ VERSION=${{ steps.validate.outputs.version }}
82+
83+ sed -i "s/#.*(Pre-release)/# V${VERSION}/g" CHANGELOG.md
84+
85+ cat << EOF > /tmp/CHANGELOG.prepend
86+ # Vx.x.x (Pre-release)
87+
88+ ## Release Highlights
89+
90+ ## Important Notes
91+
92+ ## Breaking Changes
93+ EOF
94+
95+ echo -e "$(cat /tmp/CHANGELOG.prepend)\n\n$(cat CHANGELOG.md)" > CHANGELOG.md
96+
97+ - name: Update development files
98+ run: |
99+ VERSION=${{ steps.validate.outputs.version }}
100+ cd contrib
101+ grep -rl "quay.io/oauth2-proxy/oauth2-proxy:" | \
102+ xargs sed -i "s#quay.io/oauth2-proxy/oauth2-proxy:v[0-9]\+\.[0-9]\+\.[0-9]\+#quay.io/oauth2-proxy/oauth2-proxy:v${VERSION}#g"
103+
104+ - name: Commit and push
105+ run: |
106+ VERSION=${{ steps.validate.outputs.version }}
107+
108+ git checkout -b release/v${VERSION}
109+ git commit -am "update to release version v${VERSION}"
110+ git push -u origin release/v${VERSION}
111+
112+ - name: Create PR
113+ env:
114+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+ run: |
116+ VERSION=v${{ steps.validate.outputs.version }}
117+ gh pr create -B master -H release/${VERSION} --title "release ${VERSION}" --body "Release branch and changes created by GitHub Actions. This PR should include changes to the docs, CHANGELOG and local environment files."
.github/workflows/publish-release.ymlnew file+126
@@ -0,0 +1,126 @@
1+name: Publish Release
2+run-name: ${{ github.event.pull_request.head.ref }}
3+
4+on:
5+ pull_request_target:
6+ branches:
7+ - master
8+ types:
9+ - closed
10+
11+permissions:
12+ contents: write
13+ pull-requests: write
14+
15+jobs:
16+ publish:
17+ if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/')
18+ runs-on: ubuntu-latest
19+ outputs:
20+ tag: ${{ steps.tag.outputs.version }}
21+ steps:
22+ - name: Check out code
23+ uses: actions/checkout@v3
24+ with:
25+ ref: ${{ github.event.pull_request.merge_commit_sha }}
26+ fetch-depth: 0
27+ fetch-tags: true
28+
29+ - name: Tag release
30+ run: |
31+ # Set up github-actions[bot] user
32+ git config --local user.name "github-actions[bot]"
33+ git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
34+
35+ # Get the version from the branch name
36+ branch="${{ github.event.pull_request.head.ref }}"
37+ version="${branch#release/}"
38+ echo ${version}
39+
40+ # Tag and create release
41+ git tag -a "${version}" -m "Release ${version}"
42+ echo "version=${version}" >> $GITHUB_OUTPUT
43+ id: tag
44+
45+ - name: Set up go
46+ uses: actions/setup-go@v2
47+ with:
48+ go-version: 1.19
49+
50+ - name: Get dependencies
51+ run: |
52+ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.0
53+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
54+ chmod +x ./cc-test-reporter
55+
56+ # Install go depedencies
57+ go mod download
58+
59+ - name: Build Artifacts
60+ run: make release
61+
62+ # Upload artifacts in case of workflow failure
63+ - name: Upload Artifacts
64+ uses: actions/upload-artifact@v3
65+ with:
66+ name: oauth2-proxy-artifacts
67+ path: |
68+ release/*.tar.gz
69+ release/*.txt
70+
71+ - name: Create release
72+ env:
73+ GH_TOKEN: ${{ github.token }}
74+ run: |
75+ # Get version from tag
76+ version=$(git describe --tags --abbrev=0)
77+
78+ # Extract CHANGELOG
79+ numericVersion="${version#v}"
80+ notes=$(sed -E "/^# (v|V)$numericVersion$/,/^# (v|V)/!d;//d" CHANGELOG.md)
81+
82+ # Publish release tag
83+ git push origin "${version}"
84+
85+ # Create github release
86+ gh release create "${version}" \
87+ --title "${version}" \
88+ --notes "${notes}" \
89+ --prerelease
90+
91+ # Upload artifacts
92+ gh release upload "${version}" release/*.tar.gz
93+ gh release upload "${version}" release/*.txt
94+
95+ docker:
96+ needs: publish
97+ runs-on: ubuntu-latest
98+ steps:
99+ - name: Check out code
100+ uses: actions/checkout@v3
101+ with:
102+ ref: ${{ needs.publish.outputs.tag }}
103+ fetch-depth: 0
104+ fetch-tags: true
105+
106+ - name: Set up QEMU
107+ uses: docker/setup-qemu-action@v2
108+
109+ - name: Set up Docker Buildx
110+ id: buildx
111+ uses: docker/setup-buildx-action@v2
112+
113+ - name: Login to quay.io
114+ uses: docker/login-action@v2
115+ with:
116+ registry: quay.io/oauth2-proxy
117+ username: ${{ secrets.REGISTRY_USERNAME }}
118+ password: ${{ secrets.REGISTRY_PASSWORD }}
119+
120+ - name: Build images
121+ run: |
122+ make docker-all
123+
124+ - name: Push images
125+ run: |
126+ make docker-push-all
RELEASE.md+2
@@ -1,5 +1,7 @@
11# Release
22
3+The is a legacy document to explain the manual process of creating and publishing a new release of oauth2-proxy. As of now the release process has been automated with GitHub Actions workflows. For more information have a look at the workflows `create-release.yml` and `publish-release.yml`.
4+
35Here's how OAuth2 Proxy releases are created.
46
57## Schedule