Merge pull request #2 from Loupeznik/devel #9
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
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/checkout@v4.2.1 | |
- name: Set up Go | |
uses: actions/setup-go@v5.0.2 | |
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 <dzarsky@dzarsky.eu> | |
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/upload-artifact@v4.4.3 | |
with: | |
name: deb | |
path: /tmp/*.deb | |
- uses: actions/upload-artifact@v4.4.3 | |
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/checkout@v4.2.1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2.1.0 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v4.0.0 | |
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 }}" |