|
1 | | -name: Release |
| 1 | +name: Release new version |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - tags: |
6 | | - - v* |
7 | | - |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - package.nix |
8 | 9 | jobs: |
9 | | - release: |
| 10 | + get-newer-version: |
10 | 11 | runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + new-version: ${{ steps.check.outputs.new_version }} |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-tags: true |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Extract version from package.nix |
| 22 | + id: extract |
| 23 | + run: | |
| 24 | + VERSION=$(grep -m1 'version\s*=' package.nix | sed -E 's/.*version\s*=\s*"([^"]+)".*/\1/') |
| 25 | + echo "Extracted version: $VERSION" |
| 26 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 27 | +
|
| 28 | + - name: Get latest tag |
| 29 | + id: latest |
| 30 | + run: | |
| 31 | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none") |
| 32 | + echo "Latest tag: $LATEST_TAG" |
| 33 | + echo "latest_tag=$LATEST_TAG" >> $GITHUB_OUTPUT |
| 34 | +
|
| 35 | + - name: Check if version is new |
| 36 | + id: check |
| 37 | + run: | |
| 38 | + VERSION="${{ steps.extract.outputs.version }}" |
| 39 | + LATEST="${{ steps.latest.outputs.latest_tag }}" |
| 40 | + if [ "v$VERSION" = "$LATEST" ]; then |
| 41 | + echo "No new version detected." |
| 42 | + echo "new_version=" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "New version detected: $VERSION" |
| 45 | + echo "new_version=$VERSION" >> $GITHUB_OUTPUT |
| 46 | + fi |
11 | 47 |
|
| 48 | + build-push-dockerhub: |
| 49 | + name: Build and Push to DockerHub |
| 50 | + needs: [ get-newer-version ] |
| 51 | + if: needs.get-newer-version.outputs.new-version != '' |
| 52 | + runs-on: ubuntu-latest |
12 | 53 | steps: |
13 | | - - uses: actions/checkout@v2 |
14 | | - |
15 | | - - name: Extract tag name |
16 | | - id: tag |
17 | | - run: echo ::set-output name=VERSION::$(echo "${{ github.ref }}" | sed -e 's/.*\/v\(.*\)/\1/') |
18 | | - |
19 | | - - name: Create release |
20 | | - id: create_release |
21 | | - uses: actions/create-release@v1 |
22 | | - env: |
23 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
24 | | - with: |
25 | | - tag_name: ${{ github.ref }} |
26 | | - release_name: ${{ github.ref }} |
27 | | - draft: true |
28 | | - prerelease: false |
29 | | - body: | |
30 | | - This is the ${{ github.ref }} release of Harbor Scanner Adapter for Sysdig Secure |
31 | | -
|
32 | | - ### Major Changes |
33 | | - ### Minor Changes |
34 | | - ### Bug fixes |
35 | | -
|
36 | | - - name: Build and push Docker image |
37 | | - uses: docker/build-push-action@v1 |
38 | | - with: |
39 | | - username: ${{ secrets.SYSDIGLABS_DOCKERHUB_USER }} |
40 | | - password: ${{ secrets.SYSDIGLABS_DOCKERHUB_TOKEN }} |
41 | | - repository: sysdiglabs/harbor-scanner-sysdig-secure |
42 | | - add_git_labels: true |
43 | | - dockerfile: build/Dockerfile |
44 | | - tags: latest, ${{ steps.tag.outputs.VERSION }} |
| 54 | + - name: Checkout code |
| 55 | + uses: actions/checkout@v4 |
| 56 | + |
| 57 | + - name: Install Nix |
| 58 | + uses: DeterminateSystems/nix-installer-action@main |
| 59 | + |
| 60 | + - name: Configure Nix cache |
| 61 | + uses: DeterminateSystems/magic-nix-cache-action@main |
| 62 | + |
| 63 | + - name: Build |
| 64 | + run: nix build -L .#harbor-adapter-docker |
| 65 | + |
| 66 | + - name: Load in docker |
| 67 | + run: | |
| 68 | + docker load -i ./result |
| 69 | + docker tag sysdiglabs/harbor-scanner-sysdig-secure:${{ needs.get-newer-version.outputs.new-version }} sysdiglabs/harbor-scanner-sysdig-secure:latest |
| 70 | + docker images |
| 71 | +
|
| 72 | + - name: Login to Docker Hub |
| 73 | + uses: docker/login-action@v3 |
| 74 | + with: |
| 75 | + username: ${{ secrets.SYSDIGLABS_DOCKERHUB_USER }} |
| 76 | + password: ${{ secrets.SYSDIGLABS_DOCKERHUB_TOKEN }} |
| 77 | + |
| 78 | + - name: Push to Docker Hub |
| 79 | + run: | |
| 80 | + docker push sysdiglabs/harbor-scanner-sysdig-secure:${{ needs.get-newer-version.outputs.new-version }} |
| 81 | + docker push sysdiglabs/harbor-scanner-sysdig-secure:latest |
| 82 | +
|
| 83 | + release: |
| 84 | + name: Create release at Github |
| 85 | + needs: [ get-newer-version ] |
| 86 | + if: needs.get-newer-version.outputs.new-version != '' |
| 87 | + runs-on: ubuntu-latest |
| 88 | + permissions: |
| 89 | + contents: write # Required for release creation |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + fetch-depth: 0 |
| 94 | + fetch-tags: true |
| 95 | + |
| 96 | + - name: Install Nix |
| 97 | + uses: DeterminateSystems/nix-installer-action@main |
| 98 | + |
| 99 | + - name: Configure Nix cache |
| 100 | + uses: DeterminateSystems/magic-nix-cache-action@main |
| 101 | + |
| 102 | + - name: Install git-chglog |
| 103 | + run: nix profile install nixpkgs#git-chglog |
| 104 | + |
| 105 | + - name: Tag with version v${{ needs.get-newer-version.outputs.new-version }} |
| 106 | + run: git tag v${{ needs.get-newer-version.outputs.new-version }} |
| 107 | + |
| 108 | + - name: Generate changelog |
| 109 | + run: git-chglog -c .github/git-chglog/config.yml -o RELEASE_CHANGELOG.md $(git describe --tags $(git rev-list --tags --max-count=1)) |
| 110 | + |
| 111 | + - name: Create release |
| 112 | + uses: softprops/action-gh-release@v2 |
| 113 | + with: |
| 114 | + name: v${{ needs.get-newer-version.outputs.new-version }} |
| 115 | + tag_name: v${{ needs.get-newer-version.outputs.new-version }} |
| 116 | + prerelease: false |
| 117 | + body_path: RELEASE_CHANGELOG.md |
0 commit comments