-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Loupeznik/devel
Add CI/CD
- Loading branch information
Showing
1 changed file
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
name: CI/CD | ||
|
||
on: | ||
push: | ||
branches: ["master", "devel"] | ||
tags: ["v*.*.*"] | ||
pull_request: | ||
branches: ["master"] | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
runs-on: ubuntu-latest | ||
env: | ||
GO111MODULE: on | ||
APP_NAME: 'ignoreinit' | ||
DEFAULT_BUILD_ARCH: 'amd64' | ||
|
||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: "1.23" | ||
|
||
- name: Install dependencies | ||
run: go get | ||
|
||
- name: Build | ||
shell: pwsh | ||
run: ./build.ps1 | ||
|
||
- name: Create deb | ||
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}} | ||
run: | | ||
REF=${{ github.ref_name }} | ||
APP_VERSION=${REF//v/} | ||
APP_ID=${{ env.APP_NAME }}_${APP_VERSION}_${{ env.DEFAULT_BUILD_ARCH }} | ||
TMP_DIR=/tmp/$APP_ID | ||
APP_DIR=$TMP_DIR/usr/local/bin | ||
mkdir -p $APP_DIR | ||
cp ./bin/${{ env.APP_NAME }}-${{ env.DEFAULT_BUILD_ARCH }}-linux $APP_DIR/${{ env.APP_NAME }} | ||
mkdir $TMP_DIR/DEBIAN | ||
cat <<EOF > $TMP_DIR/DEBIAN/control | ||
Package: ${{ env.APP_NAME }} | ||
Version: $APP_VERSION | ||
Architecture: ${{ env.DEFAULT_BUILD_ARCH }} | ||
Maintainer: Dominik Zarsky <[email protected]> | ||
Description: A tool for creating .gitignore files from the command line. | ||
EOF | ||
chmod +x $APP_DIR/${{ env.APP_NAME }} | ||
dpkg-deb --build --root-owner-group $TMP_DIR | ||
|
||
- name: Publish artifact | ||
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}} | ||
uses: actions/[email protected] | ||
with: | ||
name: deb | ||
path: /tmp/*.deb | ||
|
||
- uses: actions/[email protected] | ||
with: | ||
name: artifact | ||
path: ./bin/* | ||
|
||
docker: | ||
name: Docker | ||
needs: build | ||
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to the Container registry | ||
uses: docker/[email protected] | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
push: true | ||
tags: | | ||
loupeznik/ignoreinit:${{ github.ref_name }} | ||
loupeznik/ignoreinit:latest | ||
# apt: | ||
# name: APT release | ||
# needs: build | ||
# if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}} | ||
# runs-on: oc-ubuntu-4 | ||
# steps: | ||
# - uses: actions/download-artifact@v4 | ||
# with: | ||
# name: deb | ||
# path: output | ||
# | ||
# - name: Publish package | ||
# run: | | ||
# GPG_TTY=$(tty) | ||
# export GPG_TTY | ||
# | ||
# cd /opt/repo/apt | ||
# cp /tmp/dist/*.deb amd64 | ||
# | ||
# dpkg-scanpackages --arch amd64 --multiversion . > Packages | ||
# gzip -k -f Packages | ||
# | ||
# apt-ftparchive release . > Release | ||
# | ||
# echo ${{ secrets.GPG_KEY_PASSPHRASE }} > /tmp/gpg_secret | ||
# chmod 600 /tmp/gpg_secret | ||
# gpg --pinentry-mode loopback --passphrase-file "/tmp/gpg_secret" --yes -abs -u ${{ SECRETS.GPG_KEY_ID }} -o Release.gpg Release | ||
# rm /tmp/gpg_secret | ||
# rm -rf /tmp/dist | ||
|
||
release: | ||
name: Release | ||
needs: | ||
- build | ||
#- apt | ||
- docker | ||
if: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')}} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: artifact | ||
path: output | ||
|
||
- name: Create a release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
output/**/* | ||
generate_release_notes: true | ||
name: "${{ github.ref_name }}" |